Jump to content
Software FX Community

Out-Chart with raw values


SAPIENScripter
 Share

Recommended Posts

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. 

Link to comment
Share on other sites

This is an approach we use in some internal scripts

MyData.ps1

$oct = 134
$nov = 345
$dec = 239

$obj = new-object System.Object
add-member -inputobject $obj -membertype NoteProperty -Name Month -value "October"
add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $oct
Write-output $obj

$obj = new-object System.Object
add-member -inputobject $obj -membertype NoteProperty -Name Month -value "November"
add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $nov
Write-output $obj

$obj = new-object System.Object
add-member -inputobject $obj -membertype NoteProperty -Name Month -value "December"
add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $dec
Write-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.Object
add-member -inputobject $obj -membertype NoteProperty -Name Month -value "October"
add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $oct
Write-output $obj

$obj = new-object System.Object
add-member -inputobject $obj -membertype NoteProperty -Name Month -value "November"
add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $nov
Write-output $obj

$obj = new-object System.Object
add-member -inputobject $obj -membertype NoteProperty -Name Month -value "December"
add-member -inputobject $obj -membertype NoteProperty -Name Sales -value $dec
Write-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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...