2013-07-24 27 views

回答

3

您可以將Y軸設置爲使用自定義標籤而不是數字。

chart1.ChartAreas[0].AxisY.CustomLabels.Add(-0.5, 0.5, "Success"); 
chart1.ChartAreas[0].AxisY.CustomLabels.Add(0.5, 1.5, "Failure"); 

您必須設置標籤出現的範圍。這就是爲什麼我選擇「-0.5」到「0.5」的範圍(它以零爲中心)。

0

假設使用的是在X軸的字符串( 「1」 或 「0」):

//Build up 
chart1.Series.Clear(); 
chart1.ChartAreas.Clear(); 

chart1.Series.Add("S"); 
chart1.ChartAreas.Add("A"); 

chart1.Series["S"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar; 

//Creating test data 
chart1.Series["S"].Points.AddXY("1", 5); 
chart1.Series["S"].Points.AddXY("0", 3); 
chart1.Series["S"].Points.AddXY("1", 6); 
chart1.Series["S"].Points.AddXY("0", 4); 
chart1.Series["S"].Points.AddXY("1", 1); 

//Changing labels 
foreach (var p in chart1.Series["S"].Points) 
{ 
    p.AxisLabel = (p.AxisLabel == "1") ? "Success" : "Failure"; 
}