积极答复者
MsChart 堆叠柱状图间隔如何取消

问题
答案
-
Hi Z_H,
你可以尝试使用以下代码来设置series的宽度。
chart1.Series[i]["PixelPointWidth"] = "80";
Regards,
Kyle
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 Z_H 2019年7月8日 1:30
全部回复
-
Hi Z_H,
为了避免这种情况,你可以将X轴对应的DateTime类型转换为string类型。
chart1.Series.Clear(); // The date Xaxis List<DateTime> time = new List<DateTime>() { new DateTime(2019, 3, 1, 7, 0, 0), new DateTime(2019, 3, 1, 7, 1, 0), new DateTime(2019, 3, 1, 7, 6, 0) }; List<string> timestring = new List<string>(); // convert the date to string foreach (DateTime t in time) { timestring.Add(t.ToShortTimeString()); } // Add series List<string> products = new List<string>() { "A", "B", "C", "D" }; for (int i = 0; i < products.Count; i++) { Series series = new Series(); series.Name = products[i]; series.ChartType = SeriesChartType.StackedColumn; this.chart1.Series.Add(series); chart1.Series[i].XValueType = ChartValueType.DateTime; } // Bind data int[][] scores = new int[3][] { new int[] { 1, 2, 3, 4 }, new int[] { 3, 3, 3, 4 }, new int[] { 5, 2, 3, 4 } }; for (int i = 0; i < products.Count; i++) { for (int j = 0; j < scores.Length; j++) this.chart1.Series[i].Points.AddXY(timestring[j], scores[j][i]); }
测试结果如下:
Regards,
Kyle
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已编辑 Kyle Wang - MSFTMicrosoft contingent staff, Moderator 2019年7月1日 5:58
-
Hi Z_H,
你可以尝试使用以下代码来设置series的宽度。
chart1.Series[i]["PixelPointWidth"] = "80";
Regards,
Kyle
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 Z_H 2019年7月8日 1:30