Graph shows too much data in the Legend

I’m working on a script which shows me the volume growth of my filers, the input data is now complete only the graphical output has too much information.

when i generate the graph i have multiple filers with multiple aggregates.
these aggregates show up in the legend in every graph, not only the aggregates
from the current filer.

How can i limit the legend that he only shows the aggregates from the filer where they are on.

this is my script

the data is a csv file with the following columns:
Name,Date,Aggregate,TotalSize,AvailableSize,UsedSize

[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms.DataVisualization”)
$currentDate = (get-date).ToString(“yyyyMMdd”)
$data = import-csv .\Log\graph2.csv
$servers = $data | select -ExpandProperty Name -Unique | sort
$Aggregates = $data | select -ExpandProperty Aggregate -Unique | sort
foreach ($server in $servers)
{
$chart = new-object System.Windows.Forms.DataVisualization.Charting.Chart
$chartarea = new-object system.windows.forms.datavisualization.charting.chartarea
$Chart.Titles.Add("$Server")
$ChartArea.AxisX.Title = “Date”
$ChartArea.AxisY.Title = “Usage (TB)”
$chart.width = 1500
$chart.Height = 600
$chart.Left = 40
$chart.top = 30
$chart.Name = $server
$chart.ChartAreas.Add($chartarea)
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$chart.Legends.Add($legend)
foreach ($Aggregate in $Aggregates)
{
$chart.Series.Add($Aggregate)
$chart.Series[$Aggregate].Points | ForEach-Object { $.Label = $Aggregate }
$chart.Series[$Aggregate].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Line
$chart.Series[$Aggregate].BorderWidth = 4
$points = $data | Where-Object {($
.Name -eq $server) -and ($.Aggregate -eq $Aggregate)}
foreach ($point in $points)
{
$datapoint = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint($point.Date, $point.usedSize)
$chart.Series[$Aggregate].Points.Add($datapoint)
}
}
$filename = “.\Log\pictures” + $server + "
" + $currentDate + “.png”
$chart.SaveImage($filename, “PNG”)
}

You’re currently getting all the aggregates and then processing all the aggregates for all the servers. What you want to be doing is getting the aggregates on a per server basis. i.e. within the foreach server loop.

Remove this line from the top of the script:

$Aggregates = $data | select -ExpandProperty Aggregate -Unique | sort

And add this just before foreach ($aggregate in $aggregates):

$aggregates = $data | Where {$_.Name -eq $server} | Select -ExpandProperty Aggregate -Unique

This works OK with some dummy data that I setup although I’m not getting any points plotted. Some sample data would be useful if further troubleshooting is required.

He matt,

Yes, that’s it… thanks matt.
i did added -unique otherwise i got a lot of graph lines over each other…

$aggregates = $data | Where {$_.Name -eq $server} | Select -ExpandProperty Aggregate -unique

sorry, forgot to close it…

Hmm, hitting a snag…

The data on the graph is not exactly as on the table.

I only get 5 points in the graph, the date is not correct, only the start date and the end date are date -1 and date +1, but the three! (should be 7) points do not have a correct value for the date.

I’m including the script and the data file (graph2.csv)

[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms.DataVisualization”)
$currentDate = (get-date).ToString(“yyyyMMdd”)
$data = import-csv C:\NL_ITD_Powershell\PSMonitor\Scripts\Monitoring_Volume_Growth\Log\graph2.csv
$servers = $data | select -ExpandProperty Name -Unique | sort
#$Aggregates = $data | select -ExpandProperty Aggregate -Unique | sort

foreach ($server in $servers)
{
$chart = new-object System.Windows.Forms.DataVisualization.Charting.Chart
$chartarea = new-object system.windows.forms.datavisualization.charting.chartarea
$Chart.Titles.Add("$Server")
$ChartArea.AxisX.Title = “Date”
$ChartArea.AxisY.Title = “Usage (TB)”
$chart.width = 1500
$chart.Height = 800
$chart.Left = 40
$chart.top = 30
$chart.Name = $server
$chart.ChartAreas.Add($chartarea)
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$chart.Legends.Add($legend)
$aggregates = $data | Where {$_.Name -eq $server} | Select -ExpandProperty Aggregate -unique

foreach ($Aggregate in $Aggregates)
    {
    $chart.Series.Add($Aggregate)
    $chart.Series[$Aggregate].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Line
    $chart.Series[$Aggregate].BorderWidth = 4
    $points = $data | Where-Object {($_.Name -eq $server) -and ($_.Aggregate -eq $Aggregate)}
    foreach ($point in $points)
        {
        $datapoint = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint($point.Date, $point.usedSize)
        $chart.Series[$Aggregate].Points.Add($datapoint)
        }
    }
$filename = "C:\NL_ITD_Powershell\PSMonitor\Scripts\Monitoring_Volume_Growth\Log\pictures\" + $server + "_" + $currentDate + ".png"
$chart.SaveImage($filename, "PNG")
}

I have a data table:

Name,Date,Aggregate,TotalSize,AvailableSize,UsedSize
NLSTN0301,20151125,aggr0_0301_sas(57.53TB),57.53,13.02,44.51
NLSTN0301,20151125,aggr0_0301_sata(37.26TB),37.26,27.69,9.56
NLSTN0301,20151126,aggr0_0301_sas(57.53TB),57.53,12.95,44.59
NLSTN0301,20151126,aggr0_0301_sata(37.26TB),37.26,27.69,9.56
NLSTN0301,20151127,aggr0_0301_sas(57.53TB),57.53,13.02,44.51
NLSTN0301,20151127,aggr0_0301_sata(37.26TB),37.26,27.7,9.56
NLSTN0301,20151130,aggr0_0301_sas(57.53TB),57.53,12.95,44.59
NLSTN0301,20151130,aggr0_0301_sata(37.26TB),37.26,27.69,9.56
NLSTN0301,20151201,aggr0_0301_sas(57.53TB),57.53,12.56,44.97
NLSTN0301,20151201,aggr0_0301_sata(37.26TB),37.26,27.39,9.87
NLSTN0301,20151202,aggr0_0301_sas(57.53TB),57.53,12.62,44.91
NLSTN0301,20151202,aggr0_0301_sata(37.26TB),37.26,27.35,9.91
NLSTN0301,20151203,aggr0_0301_sas(57.53TB),57.53,12.67,44.86
NLSTN0301,20151203,aggr0_0301_sata(37.26TB),37.26,27.31,9.95
NLSTN0501,20151125,aggr0_0501_sas(37.44TB),37.44,7.66,29.78
NLSTN0501,20151125,aggr0_0501_sata(19.61TB),19.61,8.85,10.76
NLSTN0501,20151126,aggr0_0501_sas(37.44TB),37.44,7.65,29.79
NLSTN0501,20151126,aggr0_0501_sata(19.61TB),19.61,8.85,10.76
NLSTN0501,20151127,aggr0_0501_sas(37.44TB),37.44,7.66,29.78
NLSTN0501,20151127,aggr0_0501_sata(19.61TB),19.61,8.85,10.76
NLSTN0501,20151130,aggr0_0501_sas(37.44TB),37.44,7.9,29.54
NLSTN0501,20151130,aggr0_0501_sata(19.61TB),19.61,8.85,10.76
NLSTN0501,20151201,aggr0_0501_sas(37.44TB),37.44,7.58,29.86
NLSTN0501,20151201,aggr0_0501_sata(19.61TB),19.61,8.85,10.75
NLSTN0501,20151202,aggr0_0501_sas(37.44TB),37.44,7.56,29.88
NLSTN0501,20151202,aggr0_0501_sata(19.61TB),19.61,8.85,10.76
NLSTN0501,20151203,aggr0_0501_sas(37.44TB),37.44,7.66,29.78
NLSTN0501,20151203,aggr0_0501_sata(19.61TB),19.61,8.84,10.77
NLSTN0502,20151125,aggr0_0502_sata(52.29TB),52.29,18.3,33.99
NLSTN0502,20151125,aggr1_0502_sata(52.29TB),52.29,14.23,38.07
NLSTN0502,20151125,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0502,20151126,aggr0_0502_sata(52.29TB),52.29,18.29,34
NLSTN0502,20151126,aggr1_0502_sata(52.29TB),52.29,14.2,38.09
NLSTN0502,20151126,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0502,20151127,aggr0_0502_sata(52.29TB),52.29,18.3,33.99
NLSTN0502,20151127,aggr1_0502_sata(52.29TB),52.29,14.23,38.07
NLSTN0502,20151127,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0502,20151130,aggr0_0502_sata(52.29TB),52.29,18.57,33.72
NLSTN0502,20151130,aggr1_0502_sata(52.29TB),52.29,14.21,38.08
NLSTN0502,20151130,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0502,20151201,aggr0_0502_sata(52.29TB),52.29,18.65,33.64
NLSTN0502,20151201,aggr1_0502_sata(52.29TB),52.29,14.14,38.15
NLSTN0502,20151201,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0502,20151202,aggr0_0502_sata(52.29TB),52.29,18.84,33.46
NLSTN0502,20151202,aggr1_0502_sata(52.29TB),52.29,14.21,38.08
NLSTN0502,20151202,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0502,20151203,aggr0_0502_sata(52.29TB),52.29,18.87,33.42
NLSTN0502,20151203,aggr1_0502_sata(52.29TB),52.29,14.19,38.1
NLSTN0502,20151203,aggr2_0502_sata(26.15TB),26.15,8.68,17.47
NLSTN0503,20151125,aggr0_0503_sata(52.29TB),52.29,21.21,31.09
NLSTN0503,20151125,aggr1_0503_sata(52.29TB),52.29,31.38,20.91
NLSTN0503,20151125,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0503,20151126,aggr0_0503_sata(52.29TB),52.29,21.21,31.09
NLSTN0503,20151126,aggr1_0503_sata(52.29TB),52.29,31.38,20.91
NLSTN0503,20151126,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0503,20151127,aggr0_0503_sata(52.29TB),52.29,21.33,30.97
NLSTN0503,20151127,aggr1_0503_sata(52.29TB),52.29,31.68,20.61
NLSTN0503,20151127,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0503,20151130,aggr0_0503_sata(52.29TB),52.29,21.22,31.07
NLSTN0503,20151130,aggr1_0503_sata(52.29TB),52.29,31.36,20.93
NLSTN0503,20151130,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0503,20151201,aggr0_0503_sata(52.29TB),52.29,21.17,31.12
NLSTN0503,20151201,aggr1_0503_sata(52.29TB),52.29,31.5,20.8
NLSTN0503,20151201,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0503,20151202,aggr0_0503_sata(52.29TB),52.29,21.25,31.04
NLSTN0503,20151202,aggr1_0503_sata(52.29TB),52.29,31.54,20.76
NLSTN0503,20151202,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0503,20151203,aggr0_0503_sata(52.29TB),52.29,21.03,31.27
NLSTN0503,20151203,aggr1_0503_sata(52.29TB),52.29,31.75,20.54
NLSTN0503,20151203,aggr2_0503_sata(26.15TB),26.15,23.96,2.18
NLSTN0504,20151125,aggr0_0504_sata(41.4TB),41.4,24.04,17.36
NLSTN0504,20151126,aggr0_0504_sata(41.4TB),41.4,24.04,17.36
NLSTN0504,20151127,aggr0_0504_sata(41.4TB),41.4,24.04,17.36
NLSTN0504,20151130,aggr0_0504_sata(41.4TB),41.4,24.04,17.36
NLSTN0504,20151201,aggr0_0504_sata(41.4TB),41.4,24.04,17.36
NLSTN0504,20151202,aggr0_0504_sata(41.4TB),41.4,24.04,17.36
NLSTN0504,20151203,aggr0_0504_sata(41.40TB),41.4,24.04,17.36
NLSTN1001,20151125,aggr0_1001_sata(52.29TB),52.29,31.08,21.21
NLSTN1001,20151125,aggr1_1001_sata(52.29TB),52.29,14.97,37.33
NLSTN1001,20151125,aggr2_1001_sata(26.15TB),26.15,19.23,6.92
NLSTN1001,20151126,aggr0_1001_sata(52.29TB),52.29,31.08,21.21
NLSTN1001,20151126,aggr1_1001_sata(52.29TB),52.29,14.97,37.33
NLSTN1001,20151126,aggr2_1001_sata(26.15TB),26.15,19.23,6.92
NLSTN1001,20151127,aggr0_1001_sata(52.29TB),52.29,31.13,21.17
NLSTN1001,20151127,aggr1_1001_sata(52.29TB),52.29,15.03,37.26
NLSTN1001,20151127,aggr2_1001_sata(26.15TB),26.15,19.45,6.69
NLSTN1001,20151130,aggr0_1001_sata(52.29TB),52.29,31.05,21.24
NLSTN1001,20151130,aggr1_1001_sata(52.29TB),52.29,15.37,36.92
NLSTN1001,20151130,aggr2_1001_sata(26.15TB),26.15,19.2,6.95
NLSTN1001,20151201,aggr0_1001_sata(52.29TB),52.29,31.1,21.19
NLSTN1001,20151201,aggr1_1001_sata(52.29TB),52.29,15.5,36.79
NLSTN1001,20151201,aggr2_1001_sata(26.15TB),26.15,19.39,6.75
NLSTN1001,20151202,aggr0_1001_sata(52.29TB),52.29,31.08,21.21
NLSTN1001,20151202,aggr1_1001_sata(52.29TB),52.29,15.43,36.86
NLSTN1001,20151202,aggr2_1001_sata(26.15TB),26.15,19.36,6.78
NLSTN1001,20151203,aggr0_1001_sata(52.29TB),52.29,31.05,21.24
NLSTN1001,20151203,aggr1_1001_sata(52.29TB),52.29,15.42,36.87
NLSTN1001,20151203,aggr2_1001_sata(26.15TB),26.15,19.38,6.76
NLSTN1002,20151125,aggr0_1002_sata(52.29TB),52.29,28.75,23.55
NLSTN1002,20151125,aggr1_1002_sata(52.29TB),52.29,24.52,27.77
NLSTN1002,20151125,aggr2_1002_sata(26.15TB),26.15,22.12,4.02
NLSTN1002,20151126,aggr0_1002_sata(52.29TB),52.29,28.62,23.67
NLSTN1002,20151126,aggr1_1002_sata(52.29TB),52.29,24.3,27.99
NLSTN1002,20151126,aggr2_1002_sata(26.15TB),26.15,22.12,4.02
NLSTN1002,20151127,aggr0_1002_sata(52.29TB),52.29,28.75,23.55
NLSTN1002,20151127,aggr1_1002_sata(52.29TB),52.29,24.52,27.77
NLSTN1002,20151127,aggr2_1002_sata(26.15TB),26.15,22.13,4.02
NLSTN1002,20151130,aggr0_1002_sata(52.29TB),52.29,28.92,23.37
NLSTN1002,20151130,aggr1_1002_sata(52.29TB),52.29,24.4,27.89
NLSTN1002,20151130,aggr2_1002_sata(26.15TB),26.15,21.94,4.21
NLSTN1002,20151201,aggr0_1002_sata(52.29TB),52.29,28.85,23.44
NLSTN1002,20151201,aggr1_1002_sata(52.29TB),52.29,24.53,27.76
NLSTN1002,20151201,aggr2_1002_sata(26.15TB),26.15,21.94,4.2
NLSTN1002,20151202,aggr0_1002_sata(52.29TB),52.29,28.81,23.48
NLSTN1002,20151202,aggr1_1002_sata(52.29TB),52.29,24.66,27.63
NLSTN1002,20151202,aggr2_1002_sata(26.15TB),26.15,21.94,4.2
NLSTN1002,20151203,aggr0_1002_sata(52.29TB),52.29,28.87,23.42
NLSTN1002,20151203,aggr1_1002_sata(52.29TB),52.29,24.6,27.69
NLSTN1002,20151203,aggr2_1002_sata(26.15TB),26.15,21.96,4.19

Hmm, probably he is interpolating the numbers, how can i change this behaviour?

OK, this took some fiddling to get working as I’m not overly familiar with using charting. However, the docs on MSDN are really good and by looking at the various properties I think I’ve found the solution.
What’s happening in your code is that you’re settting a value (it’s treated as a double) for both the X and Y axis but in your case the value for X isn’t really a value, it’s just a label. What you should be doing, I think, is setting the value for X to 0 and then setting the label on the X-Axis for that datapoint.

Try this as your foreach for the points. I think it will still need some tweaking, for example, you probably don’t want the X-Axis to start at 0 but it’s getting there.

foreach ($point in $points)  {
    $datapoint = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$point.UsedSize)
    $datapoint.AxisLabel = $point.Date
    $chart.Series[$Aggregate].Points.Add($datapoint)
 
 }

Hi Matt,

you were right on the money… It did the trick. it doesn’t matter that it starts at zero, the graph looks good…

thanks for thinking along…

Stephan