简体   繁体   English

MSChart WinForms图表控件:如何在RangeBar图表上将DataPoints与Series标签对齐?

[英]MSChart WinForms Chart Control: How do I align DataPoints with Series label on RangeBar chart?

I have a win forms chart control with a RangeBar type chart where I add Series and DataPoints as follows: 我有一个带有RangeBar类型图表的Win表单图表控件,在其中添加Series和DataPoints如下:

 public void AddSeries(List<Machine> machines)
    {
        string mID="";
        chart.ChartAreas[0].AxisX.Minimum =0;
        chart.ChartAreas[0].AxisX.Maximum =machines.Count+1;           
        int x = 1;
        foreach (var m in machines)
        {
            if (x < 4)
            {
                mID = m.idMachine.ToString();
                chart.Series.Add(new Series(mID));
                chart.Series[mID].YValuesPerPoint = 2;
                chart.Series[mID].Color = Color.Magenta;
                chart.Series[mID].ChartType = SeriesChartType.RangeBar;
                chart.Series[mID]["PointWidth"] = "0.7";
                chart.Series[mID].IsVisibleInLegend = false;
                chart.Series[mID].AxisLabel = m.MachineNo + "_" + m.idMachine;
                chart.Series[mID]["DrawSideBySide"] = "true";            

                DateTime dt = new DateTime(2010, 1, 6); 
                chart.Series[mID].Points.AddXY(x, dt.ToOADate(), dt.AddDays(1).ToOADate());
            }
            x++;
        }
    }

My chart then looks as follows: 我的图表如下所示:

在此处输入图片说明

What I want is the DataPoints of Series P01_67 and P03_69 to be correctly aligned (in the middle of the series line) as with the Series P02_68. 我想要的是将P01_67和P03_69系列的DataPoint与P02_68系列正确对齐(在系列行的中间)。 Any ideas how I can do this? 有什么想法可以做到吗? Thanks! 谢谢!

If you want them aligned you need to set this property 如果希望它们对齐,则需要设置此属性

chart.Series[mID]["DrawSideBySide"] = "false";  

But then your series will not be drawn side by site and will overlap Or you can try to remove the empty series from the Chart. 但是,您的系列不会被并排绘制,并且会重叠。或者您可以尝试从图表中删除空系列。 ( Then you will need to take care of the Labels ) (那么您将需要注意标签)

Eg:- 例如:-

Check Here for more information 在这里查看更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM