SAPIENScripter Posted December 12, 2006 Report Share Posted December 12, 2006 I can easily use Out-Chart to pipe a cmdlet expression and create a chart.I can also use import-csv and create a chart. Can I "manually" create a chart by entering data directly, in essence by-passing import-csv? For example, suppose I have data like this: SalesOct 134 Nov 345 Dec 239 How could I use out-Chart to create a chart in PowerShell? I have a feeling I'm missing something simple. Quote Link to comment Share on other sites More sharing options...
JuanC Posted December 12, 2006 Report Share Posted December 12, 2006 This is an approach we use in some internal scripts MyData.ps1 $oct = 134$nov = 345$dec = 239 $obj = new-object System.Objectadd-member -inputobject $obj -membertype NoteProperty -Name Month -value "October"add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $octWrite-output $obj $obj = new-object System.Objectadd-member -inputobject $obj -membertype NoteProperty -Name Month -value "November"add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $novWrite-output $obj $obj = new-object System.Objectadd-member -inputobject $obj -membertype NoteProperty -Name Month -value "December"add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $decWrite-output $obj In our scenarios, $oct = XXX is actually something like $oct = invoke-sql or more complex code, the key idea here is that we create objects and add as many properties as desired. Note that by writing the objects to the pipeline you separate your business logic from the presentation so you can do things like MyData | out-chart MyData | where {$_.Sales -gt 200} | out-chart You could also try the approach described by Marco Shaw on this post This is an approach we use in some internal scripts MyData.ps1 $oct = 134$nov = 345$dec = 239 $obj = new-object System.Objectadd-member -inputobject $obj -membertype NoteProperty -Name Month -value "October"add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $octWrite-output $obj $obj = new-object System.Objectadd-member -inputobject $obj -membertype NoteProperty -Name Month -value "November"add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $novWrite-output $obj $obj = new-object System.Objectadd-member -inputobject $obj -membertype NoteProperty -Name Month -value "December"add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $decWrite-output $obj In our scenarios, $oct = XXX is actually something like $oct = invoke-sql or more complex code, the key idea here is that we create objects and add as many properties as desired. Note that by writing the objects to the pipeline you separate your business logic from the presentation so you can do things like MyData | out-chart MyData | where {$_.Sales -gt 200} | out-chart You could also try the approach described by Marco Shaw on this post http://community.softwarefx.com/forums/t/9223.aspx Regards, JuanC Quote Link to comment Share on other sites More sharing options...
SAPIENScripter Posted December 12, 2006 Author Report Share Posted December 12, 2006 That will work for what I'm working on. It's a little more involved for on-the-fly charting than I would have hoped but do-able. Quote Link to comment Share on other sites More sharing options...
JuanC Posted December 12, 2006 Report Share Posted December 12, 2006 We support arrays in out-chart so you can say 10,20,12 | out-chart Using variables you can also do $a = 10,20,12 $a | out-chart Personally I think that the "creating objects" approach scales better, if you find out you are interested in another "field" you just add another property, also you can use your script for things other than a chart. If you want to show something else in the tooltip you can also do that. JuanC Quote Link to comment Share on other sites More sharing options...
SAPIENScripter Posted December 12, 2006 Author Report Share Posted December 12, 2006 I like the object approach, and for the most part that is what I need. The array trick is what I was looking for in terms of "on the fly" charting. I thought an array would work, I just couldn't get the syntax worked out. Much easier than I was trying to make it. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.