我在VS 3.5框架中的图表控件有问题。我正在尝试绘制x轴为0且y轴为1的图形,但是它的结果是绘制了(1,1)
我有一种情况,我需要用(0,1)设置一个单杠。
Chart1.Series[0].Points.Add(new DataPoint(0,1));
或者
Chart1.Series[0].Points.AddXY(0,1);
结果:
条形图(1,1)而不是显示(0,1)点
我已经添加了
Chart1.ChartAreas[""].AxisX.Minimum = 0;
仍显示相同的结果...
这太令人沮丧了:当我再增加一个点(1,1)
例如:
Chart1.Series[0].Points.AddXY(0,1);
Chart1.Series[0].Points.AddXY(1,1);
然后结果:
正确显示点(0,1)和(1,1)的条形图
您遇到此问题是因为添加到图表的默认系列是条形图。您必须删除条形图系列并将其替换为Point系列,才能显示数据。请参见下面的示例代码。
// clear data from the chart
chart.Series.Clear();
// add an x-y series to the chart
var xySeries = new Charting.Series() {
LegendText = "XY Plot",
ChartType = Charting.SeriesChartType.Point,
Color = Color.Brown,
MarkerStyle = Charting.MarkerStyle.Circle,
MarkerSize = 10
};
chart.Series.Add(xySeries);
// put your point on the series
xySeries.Points.AddXY(1, 1);
// set the axis
chart.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = Charting.ChartDashStyle.Dot;
chart.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = Charting.ChartDashStyle.Dot;
这将产生以下图表
您将必须添加此using
语句以将其包含Charting
在可用的名称空间中。
using Charting = System.Windows.Forms.DataVisualization.Charting;
要更改X轴上的标签,您将必须使用AxisLabel
DataPoint的属性。请参阅以下示例:
// put your point on the series
xySeries.Points.AddXY(0, 1);
xySeries.Points[0].AxisLabel = "0"; // <--- SET AXIS LABEL HERE
这样做会“强制”图表控件显示您选择的轴标签。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句