none
MsChart 堆叠柱状图间隔如何取消 RRS feed

  • 问题

  • 目前有一个项目需要使用堆叠柱形图准备使用微软自带的MSChart,x轴是时间类型的,一分钟一个堆叠图,但是现在有个问题就是每组堆叠图中间都有一个间隔,因为我x轴是时间这个间隔有时候会被认为是缺少数据,所以么设置可以把这个间隔取消?

    2019年6月28日 8:12

答案

  • 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
    2019年7月4日 9:59
    版主

全部回复

  • 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.

    2019年7月1日 5:35
    版主
  • 抱歉由于我账号没有验证无法发送图片,可能是我表述不清,我的意思是取消掉每组柱形图之间的白色间隔,就像你的测试结果,我是想取消7:00 AM与7:01AM两组柱形图之间的白色间隔,也就是让两组柱形图紧挨着
    2019年7月4日 9:22
  • 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
    2019年7月4日 9:59
    版主
  • 这种做法是需要根据当前控件尺寸以及绘制的数据数量计算出每个数据占据的宽度,目前我也并未找到更好的做法,就先采取这个措施吧.
    2019年7月8日 1:30