Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180923

Error getting the chart

$
0
0

Hi,

 

I am having issues getting the pie chart using the below function

 

Please help

 

function New-Piechart() {

    Param (

        [string]$FileName,

        [float]$CapacitySpace,

        [float]$SnapshotSpace,

        [float]$VolumeSpace

    )

       

    [void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    [void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")

   

    $chart = New-Object System.Windows.Forms.DataVisualization.charting.chart

    $chart.Width = 900

    $chart.Height = 600

    $chart.Left = 10

    $chart.Top = 10

 

    $chartArea = New-Object System.Windows.Forms.DataVisualization.charting.chartArea

    $chart.chartAreas.Add($chartArea)

    [void]$chart.Series.Add("Data")

   

       $legend = New-Object system.Windows.Forms.DataVisualization.charting.Legend

       $legend.Name = "Legend"

    $legend.Font = "Proxima Nova"

       $legend.Alignment = "Center"

       $legend.Docking = "top"

       $legend.Bordercolor = "#FE5000"

       $legend.Legendstyle = "row"

    $chart.Legends.Add($legend)

 

    $datapoint = New-Object System.Windows.Forms.DataVisualization.charting.DataPoint(0, $capacitySpace)

    $datapoint.AxisLabel = "Physical Capacity " + "(" + $("{0:N0}" -f $capacitySpace) + " GB)"

    $chart.Series["Data"].Points.Add($datapoint)

       

    $datapoint = New-Object System.Windows.Forms.DataVisualization.charting.DataPoint(0, $snapSpace)

    $datapoint.AxisLabel = "SnapShots " + "(" + $snapSpace + " GB)"

    $chart.Series["Data"].Points.Add($datapoint)

       

    $datapoint = New-Object System.Windows.Forms.DataVisualization.charting.DataPoint(0, $volumeSpace)

    $datapoint.AxisLabel = "Volumes " + "(" + $volumeSpace + " GB)"

    $chart.Series["Data"].Points.Add($datapoint)

       

    $chart.Series["Data"].chartType = [System.Windows.Forms.DataVisualization.charting.SerieschartType]::Pie

    $chart.Series["Data"]["PieLabelStyle"] = "Outside"

    $chart.Series["Data"]["PieLineColor"] = "#FE5000"

    $chart.Series["Data"]["PieDrawingStyle"] = "Concave"

    ($chart.Series["Data"].Points.FindMaxByValue())["Exploded"] = $true

 

    $Title = New-Object System.Windows.Forms.DataVisualization.charting.Title

    $chart.Titles.Add($Title)

    $chart.Titles[0].Text = "Capacity Usage Visualization"

    $chart.SaveImage($FileName + ".png","png")

 

    $Script:PiechartImgSrc = ConvertTo-Base64 ($FileName + ".png")

    Remove-Item -Path ($FileName + ".png")

}

 

New-Piechart -FileName ($OutFilePath + "\TempPiechart") -CapacitySpace $capacitySpace -SnapshotSpace $snapSpace -VolumeSpace $volumeSpace

 

Error :

 

Exception calling "FindMaxByValue" with "0" argument(s): "Object reference not set to an instance of an object."

At D:\myreports\Capacity_Report_2.0 - Copy.ps1:85 char:2

+     ($chart.Series["Data"].Points.FindMaxByValue())["Exploded"] = $true

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : NullReferenceException

 

Exception calling "SaveImage" with "2" argument(s): "Object reference not set to an instance of an object."

At D:\myreports\Capacity_Report_2.0 - Copy.ps1:90 char:5

+     $chart.SaveImage($FileName + ".png","png")

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : NullReferenceException

 

Exception calling "ToBase64String" with "1" argument(s): "Value cannot be null.

Parameter name: inArray"

At D:\myreports\Capacity_Report_2.0 - Copy.ps1:36 char:9

+     return [Convert]::ToBase64String((Get-Content $ImgSrc -Encoding byte))

+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentNullException


Viewing all articles
Browse latest Browse all 180923

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>