有没有办法在MSChart折线图中对齐标签?

时间:2015-03-13 20:57:50

标签: c# winforms charts mschart

我在Visual Studio 2013中使用MSChart并得到一些非常奇怪的结果。在折线图上,当绘制点图时,标签在图表上显示较低值的点,这在视觉上是混乱的。请参阅以下内容:

enter image description here

图表标签设置如下:

        recentFailureChart.Series["FailureCount"].BorderWidth = 3;
            recentFailureChart.Series["FailureCount"].Color = Color.Red;
            recentFailureChart.Series["FailureCount"].LabelBackColor = Color.Red;
            recentFailureChart.Series["FailureCount"].LabelBorderColor = Color.Black;
            recentFailureChart.Series["FailureCount"].LabelBorderDashStyle = ChartDashStyle.Solid;
            recentFailureChart.Series["FailureCount"].LabelBorderWidth = 1;
            recentFailureChart.Series["FailureCount"].LabelForeColor = Color.White;
        SmartLabelStyle smartLabel = new SmartLabelStyle();
        smartLabel.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Partial;
        smartLabel.IsMarkerOverlappingAllowed = true;
        recentFailureChart.Series["FailureCount"].SmartLabelStyle = smartLabel;

在构造函数和函数中添加点:

        recentFailureChart.Series["FailureCount"].Points.InsertY(0, failCount);
        recentFailureChart.Series["FailureCount"].Points[0].Font = labelFont;

关于如何以正确的顺序获得它们的任何想法,甚至是关于它们本身的想法?

2 个答案:

答案 0 :(得分:0)

我无法看到上面附带的图表图像有任何问题,点14和12正确地绘制在5,3和1的低点之上。我唯一注意到的是,并非所有点都是在图表中可见,可以通过将Y轴的最大值设置为更高的值(如100,使用Chart1.ChartAreas(0).AxisY.Maximum = 100来更改。

答案 1 :(得分:0)

我相信您正在寻找的属性是:

MaxMovingDistance  
MinMovingDistance  
MovingDirection  
AllowOutsidePlotArea  

一个。如果标签可以与X轴重叠,则设置AllowOutsidePlotArea。

B中。将MovingDirection设置为Top以强制所有标签显示在DataPoint上。

℃。你也可以让X轴穿过Y轴在-2或类似的东西上,为plotarea里面的智能标签腾出空间。