ChartControl - 如何在 X 轴上绘制一条线(x - 固定坐标,y - 无穷大)
ChartControl - How to plot a line on X Axis (x - fixed coordinate, y - infinity)
我正在开发一个 C# winforms 应用程序,我想在其中绘制 X 轴上的线条,使 X 坐标为固定值,但没有指定 Y 坐标。
像这样:
这可以做到吗?
Stripline 成功了!
代码如下:
public Series series1 = new Series
{
Name = "Series1",
Color = Color.Black,
IsVisibleInLegend = false,
ChartType = SeriesChartType.Line,
BorderWidth = 0,
XValueType = ChartValueType.Double,
YValueType = ChartValueType.Double
};
public StripLine startPositionLine = new StripLine
{
BorderColor = Color.Red,
BorderWidth = 2,
IntervalOffset = 7
};
public StripLine endPositionLine = new StripLine
{
BorderColor = Color.Blue,
BorderWidth = 2,
IntervalOffset = 11
};
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series.Clear();
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Interval = 1;
//Apparently some series with some points have to be present on the chart before the striplines get displayed
series1.Points.AddXY(0, 0);
series1.Points.AddXY(10, 0);
chart1.Series.Add(series1);
chart1.ChartAreas[0].AxisX.StripLines.Add(startPositionLine);
chart1.ChartAreas[0].AxisX.StripLines.Add(endPositionLine);
chart1.Invalidate();
}
下面是带状线的绘制方式:
我需要检查的一件事是在绘制带状线之前是否需要先绘制一个系列。
我正在开发一个 C# winforms 应用程序,我想在其中绘制 X 轴上的线条,使 X 坐标为固定值,但没有指定 Y 坐标。
像这样:
这可以做到吗?
Stripline 成功了!
代码如下:
public Series series1 = new Series
{
Name = "Series1",
Color = Color.Black,
IsVisibleInLegend = false,
ChartType = SeriesChartType.Line,
BorderWidth = 0,
XValueType = ChartValueType.Double,
YValueType = ChartValueType.Double
};
public StripLine startPositionLine = new StripLine
{
BorderColor = Color.Red,
BorderWidth = 2,
IntervalOffset = 7
};
public StripLine endPositionLine = new StripLine
{
BorderColor = Color.Blue,
BorderWidth = 2,
IntervalOffset = 11
};
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series.Clear();
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Interval = 1;
//Apparently some series with some points have to be present on the chart before the striplines get displayed
series1.Points.AddXY(0, 0);
series1.Points.AddXY(10, 0);
chart1.Series.Add(series1);
chart1.ChartAreas[0].AxisX.StripLines.Add(startPositionLine);
chart1.ChartAreas[0].AxisX.StripLines.Add(endPositionLine);
chart1.Invalidate();
}
下面是带状线的绘制方式:
我需要检查的一件事是在绘制带状线之前是否需要先绘制一个系列。