Advertisement
easternnl

SQL to Chart with PowerShell

Mar 15th, 2016
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")
  2. $outputpath=$env:USERPROFILE
  3.  
  4. # chart object
  5.    $chart1 = New-object System.Windows.Forms.DataVisualization.Charting.Chart
  6.    $chart1.Width = 1024*2
  7.    $chart1.Height = 1024
  8.    $chart1.BackColor = [System.Drawing.Color]::White
  9.  
  10. # title
  11.    [void]$chart1.Titles.Add("User logon times")
  12.    $chart1.Titles[0].Font = "Arial,13pt"
  13.    $chart1.Titles[0].Alignment = "topLeft"
  14.  
  15. # chart area
  16.    $chartarea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
  17.    $chartarea.Name = "ChartArea1"
  18.    $chartarea.AxisY.Title = "Seconds"
  19.    $chartarea.AxisX.Title = "Date"
  20.    $chartarea.AxisY.Interval = 10
  21.    $chartarea.AxisX.Interval = 7
  22.    $chart1.ChartAreas.Add($chartarea)
  23.  
  24. # legend
  25.    $legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
  26.    $legend.name = "Legenda"
  27.    $chart1.Legends.Add($legend)
  28.  
  29. <#
  30. # data source
  31.    $datasource = Get-Process | sort PrivateMemorySize -Descending  | Select-Object -First 5
  32.  
  33. # data series
  34.    [void]$chart1.Series.Add("VirtualMem")
  35.    $chart1.Series["VirtualMem"].ChartType = "Column"
  36.    $chart1.Series["VirtualMem"].BorderWidth  = 3
  37.    $chart1.Series["VirtualMem"].IsVisibleInLegend = $true
  38.    $chart1.Series["VirtualMem"].chartarea = "ChartArea1"
  39.    $chart1.Series["VirtualMem"].Legend = "Legend1"
  40.    $chart1.Series["VirtualMem"].color = "#62B5CC"
  41.    $datasource | ForEach-Object {$chart1.Series["VirtualMem"].Points.addxy( $_.Name , ($_.VirtualMemorySize / 1000000)) }
  42.  
  43. # data series
  44.    [void]$chart1.Series.Add("PrivateMem")
  45.    $chart1.Series["PrivateMem"].ChartType = "Column"
  46.    $chart1.Series["PrivateMem"].IsVisibleInLegend = $true
  47.    $chart1.Series["PrivateMem"].BorderWidth  = 3
  48.    $chart1.Series["PrivateMem"].chartarea = "ChartArea1"
  49.    $chart1.Series["PrivateMem"].Legend = "Legend1"
  50.    $chart1.Series["PrivateMem"].color = "#E3B64C"
  51.    $datasource | ForEach-Object {$chart1.Series["PrivateMem"].Points.addxy( $_.Name , ($_.PrivateMemorySize / 1000000)) }
  52.  
  53. #>
  54.     [void]$chart1.Series.Add("LogonTime")
  55.    $chart1.Series["LogonTime"].ChartType = "Column"
  56.    $chart1.Series["LogonTime"].BorderWidth  = 3
  57.    $chart1.Series["LogonTime"].IsVisibleInLegend = $true
  58.    $chart1.Series["LogonTime"].chartarea = "ChartArea1"
  59.    $chart1.Series["LogonTime"].Legend = "Legenda"
  60.    $chart1.Series["LogonTime"].color = "#62B5CC"
  61.    $DataSet.Tables[0] | ForEach-Object {$chart1.Series["LogonTime"].Points.addxy( $_.EasyDate , $_.InteractiveDesktop) }
  62.  
  63. # save chart
  64.    $chart1.SaveImage("$outputpath\SplineArea.png","png")
  65.  
  66.    Start-Process "C:\Program Files\Internet Explorer\iexplore.exe" -ArgumentList "$outputpath\SplineArea.png"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement