寻求一些帮助。
当我使用System.Windows.Forms.DataVisualization.Charting.Chart绘制图表时 Y轴用科学记数法格式化 - 假设为我想要的小数。 我有一个简单的数据集包含在一个$ 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))
}
生成图表时,Y轴如下所示:
这些值以正确的格式写入控制台,如何将它们添加到图表系列中作为Decimal / Prevent系列以科学计数法显示它们?
提前致谢。
答案 0 :(得分:0)
您可以使用custom numeric format string作为Y轴,如下所示:
$chartarea.AxisY.LabelStyle.Format = "##.###############";
以下是更完整的示例:
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()