C#图表对象不在xaxis上应用负点 [英] C# chart object not applying negative points on xaxis
本文介绍了C#图表对象不在xaxis上应用负点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试在C#(2013)中实现一个简单的折线图,在X轴和Y轴上应用一系列负值到正值。但是,图表不接受X轴的负系列点。 -100到+100的值正确显示在X轴上,但-50Y值来自0X轴值位置。我做错了什么?
C#代码:
Trying to implement a simple line chart in C# (2013) that applies a series of negative to positive values on both the X and Y axis. However the chart does not accept the negative Series points for the X axis. The -100 to +100 values are properly displayed on the X axis, but the -50 "Y" value originates at the "0" X axis value position. What am I doing wrong?
The C# code:
public void DrawSampleChart()
{
Graph.Chart chart = new Graph.Chart();
chart.Dock = DockStyle.Fill;
Main.ChartPanel.Controls.Clear();
Main.ChartPanel.Controls.Add(chart);
chart.ChartAreas.Add(new Graph.ChartArea());
// Define the horizontal ("X") axis attributes
chart.ChartAreas[0].AxisX.Minimum = -100.0;
chart.ChartAreas[0].AxisX.Maximum = 100.0;
chart.ChartAreas[0].AxisX.Interval = 10;
// Define the vertical ("Y") axis attributes
chart.ChartAreas[0].AxisY.Minimum = -100;
chart.ChartAreas[0].AxisY.Maximum = 100;
chart.ChartAreas[0].AxisY.Interval = 10;
// Add sample series
Graph.Series series = new Graph.Series("Series1");
series.ChartType = Graph.SeriesChartType.Line;
for (int n = -50; n <= 50; n++)
series.Points.Add(n, n);
chart.Series.Add(series);
}
我的尝试:
上面的代码在Visual Studio 2013上编译并执行。
What I have tried:
The above code compiles and executes on Visual Studio 2013.
推荐答案
发现问题。更改代码如下
Found the problem. Changed the code as follows
for (int n = -50; n <= 50; n++)
//series.Points.Add(n, n); // this was wrong
series.Points.Add(new Graph.DataPoint(n,n));
chart.Series.Add(series);
这篇关于C#图表对象不在xaxis上应用负点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文