powershell

sethayes

·

42Chart

·

Powershell

·

Total Size: 2.88 KB

·

·

Created: 5 years ago

·

Edited: 5 years ago

[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization") $scriptPath = "C:\Users\Public\Reports\img" Connect-MySqlServer -ComputerName MSILT -Port 3306 -Database labtech -Credential (Get-Credential) # Data Source $locations = Invoke-MySqlQuery "SELECT DISTINCT locationID FROM plugin_speedtest" ForEach ($location in $locations) { $loc = $location.locationID $dataSource = Invoke-MySqlQuery "SELECT clients.name AS `client`,locations.Name,plugin_speedtest.download,plugin_speedtest.upload,plugin_speedtest.date,plugin_speedtest.ping FROM plugin_speedtest LEFT JOIN locations ON locations.locationID = plugin_speedtest.locationID LEFT JOIN clients ON clients.clientid = locations.clientid WHERE plugin_speedtest.locationID = $loc" $client = Invoke-MySqlQuery "SELECT clients.name FROM clients LEFT JOIN locations ON locations.clientID = clients.clientID WHERE locations.locationID = $loc" $chart1 = New-Object System.Windows.Forms.DataVisualization.Charting.Chart $chart1.Width = 600 $chart1.Height = 400 $chart1.BackColor = [System.Drawing.Color]::White [void]$chart1.Titles.Add("Test Internet Speed Graph") $chart1.Titles[0].Font = "Segoe UI,13pt" $chart1.Titles[0].Alignment = "topLeft" $chartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea $chartArea.Name = "ChartArea1" $chartArea.AxisY.Title = "Speed (Mb/s)" $chartArea.AxisX.Title = "Date" $chartArea.AxisY.Interval = 5 $chartArea.AxisX.Interval = 1 $chartArea.AxisY.MaximumAutoSize = $false $chartArea.AxisX.MaximumAutoSize = $false $chartArea.AxisY.Maximum = 80 $chart1.ChartAreas.Add($chartArea) $legend = New-Object System.Windows.Forms.DataVisualization.Charting.Legend $legend.Name = "Legend1" $chart1.Legends.Add($legend) # Data Series [void]$chart1.Series.Add("Upload") $chart1.Series["Upload"].ChartType = "Line" $chart1.Series["Upload"].BorderWidth = 3 $chart1.Series["Upload"].IsVisibleInLegend = $True $chart1.Series["Upload"].ChartArea = "ChartArea1" $chart1.Series["Upload"].Legend = "Legend1" $chart1.Series["Upload"].Color = "#7CB5EC" ForEach ($point in $dataSource) {$chart1.Series["Upload"].Points.addxy($($point.date),[math]::Round(($($point.upload) / 1024),2))} [void]$chart1.Series.Add("Download") $chart1.Series["Download"].ChartType = "Line" $chart1.Series["Download"].BorderWidth = 3 $chart1.Series["Download"].IsVisibleInLegend = $True $chart1.Series["Download"].ChartArea = "ChartArea1" $chart1.Series["Download"].Legend = "Legend1" $chart1.Series["Download"].Color = "#FFA500" ForEach ($point in $dataSource) {$chart1.Series["Download"].Points.addxy($($point.date),[math]::Round(($($point.download) / 1024),2))} $filename = $($client.name).replace(" ","") + "_" + $location[0].replace(" ","") + "_SpeedChart" + ".png" $chart1.SaveImage("$scriptPath\$filename","png") }

1 bit

997 views

Are you sure you want to delete?