簡體   English   中英

Powershell圖表軸數據類型問題

[英]Powershell Chart Axis Datatype issue

尋找幫助。

當我使用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系列以科學計數形式顯示?

提前致謝。

您可以為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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM