我可以删除/隐藏特定的图表网格线吗?

问题描述 投票:0回答:1

我想删除/隐藏特定的ms图表网格线,这可能吗?

enter image description here

c# mschart
1个回答
1
投票

这是一个覆盖图表区域的一个例子,白色RectangleAnnotation

enter image description here

// a few references:
ChartArea ca = chart.ChartAreas[0];
Axis ax = ca.AxisX;
Axis ay = ca.AxisY;
// create an annotation
var ra = new RectangleAnnotation();
// by default anotations are positioned in percentages
// we associate it with axes to change positioning to axis values:
ra.AxisX = ax;
ra.AxisY = ay;
// our colors:
ra.LineColor = Color.White;
// for testing I use a semi-transparent color:
ra.BackColor = Color.FromArgb(222, Color.White);
// the values of the last point in my series:
double vxLast = chart.Series[0].Points.Last().XValue;
double vyLast = chart.Series[0].Points.Last().YValues[0];
// the top right of the chartarea:
double vxEnd = ax.Maximum;
double vyEnd = ay.Maximum;
// we position the annotation
ra.X = vxLast;
ra.Y = vyEnd;
// by default annotations are as large as we set them to be
// I cheat by clipping it to my chartarea:
ra.ClipToChartArea = ca.Name;
// now it is enough to make them really large:
ra.Width = 9999;
ra.Height = 9999;
// done. now we show it:
chart.Annotations.Add(ra);

当然,如果你想要,你可以计算出确切的宽度和高度。

注释应该打印并保存,缩放等。

© www.soinside.com 2019 - 2024. All rights reserved.