Chart X軸 兩行文字

789789789789
大家好

我想在 Chart的X軸 標示兩行 如下圖紅線 也就是除了Q1 Q2 Q3 Q4 外 還有年分
https://i.imgur.com/w0HAo8n.png

但我目前只能畫出下圖這樣 年分不知道怎麼畫
https://i.imgur.com/kgnSTbk.png

請問有人知道要怎麼畫嗎?

謝謝大家


程式碼載點如下
https://www.sendspace.com/file/1emu9p

程式碼如下
Chart1.ChartAreas.Add("ChartArea1"); //圖表區域集合
Chart1.Width = 800; // 圖表寬度
Chart1.Height = 500;// 圖表高度
string[] xValues = { "Q2", "Q3", "Q4", "Q1", "Q2", "Q3", "Q4", "Q1", "Q2" };
string[] yValues = { "0.32", "0.22", "0.16", "0.02", "0.08", "0.15", "0.09", "0.09", "0.05" };

Series series = new Series("Spline");
series.ChartType = SeriesChartType.Line;
series.BorderWidth = 3;
series.Points.DataBindXY(xValues, "X", yValues, "Y");
series.IsValueShownAsLabel = true;
series.Font = new Font("Times New Roman", 14);
series.MarkerSize = 12;
series.MarkerStyle = MarkerStyle.Circle;
Chart1.Series.Add(series);

Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = true;
Chart1.ChartAreas["ChartArea1"].AxisY.LineWidth = 0;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorTickMark.Enabled = false;
789789789789
我在底下這個連結找到解答 透過 CustomLabels 的設定就可以了
https://social.msdn.microsoft.com/Forums/en-US/cdf688a4-d4eb-4f2e-9926-df3df8b51ec4/change-chart-xaxis-values?forum=vbgeneral

畫出來像這樣
https://i.imgur.com/g1IRmRO.png


程式碼載點如下
https://www.sendspace.com/file/bcsm7u


程式碼如下 給和我有一樣問題的人參考

Chart1.ChartAreas.Add("ChartArea1"); //圖表區域集合
Chart1.Width = 800; // 圖表寬度
Chart1.Height = 500;// 圖表高度
string[] xValues = { "Q2", "Q3", "Q4", "Q1", "Q2", "Q3", "Q4", "Q1", "Q2" };
string[] yValues = { "0.32", "0.22", "0.16", "0.02", "0.08", "0.15", "0.09", "0.09", "0.05" };

Series series = new Series("Spline");
series.ChartType = SeriesChartType.Line;
series.BorderWidth = 3;
series.Points.DataBindXY(xValues, "X", yValues, "Y");
series.IsValueShownAsLabel = true;
series.Font = new Font("Times New Roman", 14);
series.MarkerSize = 12;
series.MarkerStyle = MarkerStyle.Circle;
Chart1.Series.Add(series);

Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = true;
Chart1.ChartAreas["ChartArea1"].AxisY.LineWidth = 0;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorTickMark.Enabled = false;

Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(1, 3, "108", 1, LabelMarkStyle.LineSideMark);
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(4, 7, "109", 1, LabelMarkStyle.LineSideMark);
Chart1.ChartAreas["ChartArea1"].AxisX.CustomLabels.Add(8, 9, "110", 1, LabelMarkStyle.LineSideMark);
MIS2000 Lab
感謝分享 :-) 謝謝您

讚!
回到頂部