2015-05-28 31 views
2

目前我使用N2格式這樣格式化C#圖表座標軸使用的CultureInfo

chart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:N2}"; 

我想達到什麼樣的設置我的圖表的Y軸是N2採用印尼格式,我知道如何做到這一點的對象轉換就像下面

sum.ToString("N2", CultureInfo.GetCultureInfo("id-ID")); 

如何格式化圖表軸申請的CultureInfo?

+0

哪些圖表組件,您正在使用?分享鏈接到它的文檔 –

+0

我使用的圖表組件從Visual Studio 2013本身,而不是第三方組件 –

回答

3

您可以使用圖表的FormatNumber事件。

private readonly CultureInfo indonesiaCulture = CultureInfo.GetCultureInfo("id-ID"); 
void chart1_FormatNumber(object sender, FormatNumberEventArgs e) 
{ 
    if (e.ElementType == ChartElementType.AxisLabels) 
    { 
     e.LocalizedValue = e.Value.ToString("N2", indonesiaCulture); 
    } 
} 

或者您可以更改爲Thread.CurrentUICulture UI線程和設定LabelStyle.Format屬性。我沒有測試過,我相信這也應該起作用。

+0

很好,效果很好,我已經接受你的答案,謝謝你 –

1

除了Sriram Sakthivel的回答。 您可以使用Format屬性是這樣的:

chart.ChartAreas[0].AxisY.LabelStyle.Format = "IndonesianNumericFormat"; 

void chart_FormatNumber(object sender, FormatNumberEventArgs e) 
{ 
    switch (e.Format) 
    { 
     case "IndonesianNumericFormat": 
      e.LocalizedValue = e.Value.ToString("N2", new CultureInfo("id-ID")); 
      break; 
    } 
} 

所以,你可以設置不同的格式,不同的列並串轉換的incapsulate邏輯一類\廠等