looking for some assistance.
When I draw a chart using System.Windows.Forms.DataVisualization.Charting.Chart The Y axis is formatted in scientific notation - as supposed to decimal which I desire. I have a simple dataset contained within a single $hashtable.
# data source
$datasource = @{London = 0.000000512; Berlin = 0.000000520; Madrid = 0.000000519; Rome = 0.000000518; Paris = 0.000000503}
foreach ($h in $datasource.Keys)
{
echo ( "${h} $([decimal]$datasource.Item($h))" )
$chart1.Series["Price"].Points.addxy( $h ,[decimal]$datasource.Item($h))
}
When the chart is produced the Y axis looks like so:
These values write to console in the correct format, how can I add them to the chart series as type Decimal/Prevent the series showing them in scientific notation?
Thanks in advance.
You can use a custom numeric format string for the Y-Axis like this:
$chartarea.AxisY.LabelStyle.Format = "##.###############";
Here is more complete example:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms.DataVisualization
$chart1 = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$chart1.Width = 400
$chart1.Height = 400
$chartarea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$chartarea.AxisY.LabelStyle.Format = "##.###############";
$chartarea.AxisY.Minimum = 0.0000005
$chartarea.AxisY.Maximum = 0.00000052
$chart1.ChartAreas.Add($chartarea)
$chart1.Titles.Add("The Price") | Out-Null
$chart1.Series.Add("Price") | Out-Null
$chart1.Series[0].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Line
$chart1.Series[0].YValueType = [System.Windows.Forms.DataVisualization.Charting.ChartValueType]::Double
# data source
$datasource = @{London = 0.000000512; Berlin = 0.000000520; Madrid = 0.000000519; Rome = 0.000000518; Paris = 0.000000503}
foreach ($h in $datasource.Keys)
{
echo ( "${h} $([decimal]$datasource.Item($h))" )
$chart1.Series["Price"].Points.addxy( $h ,[decimal]$datasource.Item($h))
}
$chart1.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor `
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right -bor `
[System.Windows.Forms.AnchorStyles]::Top
$form = New-Object Windows.Forms.Form
$form.Width = 450
$form.Height = 450
$form.Controls.Add($chart1)
$form.ShowDialog()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.