对于点图表,ASP.NET图表轴显示为离散而非连续

时间:2012-05-18 15:58:45

标签: c# asp.net

我使用标准的ASP.NET Chart控件从以下数据创建点图:

X         Y 
32.6768,  1
32.6768,  2
32.6768,  3
32.6768,  4
32.678,   5
32.678,   6
187.862,  1
187.862,  2

数据被读入DataTable解析为Double类型的图表,数据绑定到该类型。控件找到数据并绘制它,但不是如预期的那样,如下所示:

ASP.NET Chart

如图所示,轴是离散的而不是连续的。标签显示正常,包括单个数据点。代码中设置了以下设置:

ASP.NET:

<asp:Series Name="DataSeries" XValueType="Double" YValuesPerPoint="25">
// 25 used in case other data sets are larger

C#Backend:

chtData.Series["DataSeries"].ChartType = SeriesChartType.Point;

DataView dv = new DataView(/* DataTable Instance */);
chtData.Series["DataSeries"].Points.DataBind(dv, /* X-axis column title */, */ Y-axis column title */, "");

我应该设置任何其他属性来更正图表显示吗?这是ChartArea问题而不是Series问题吗?

根据要求,这是填充DataTable实例的代码。来自传入字符串的数据被分成单独的行(\n字符)。然后,每个行按值之间的空格分隔:

string[] row = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (!columnsFound)
{
    // columns: int to hold number of columns required in DataTable
    columns = row.GetLength(0);
    columnsFound = true;
    if (columns == 4) this.DataPoints.Columns.Add("Label");    // Labels for data points
    this.DataPoints.Columns.Add(this.XAxis);    // string with X-axis label
    this.DataPoints.Columns.Add(this.YAxis);    // string with Y-axis label
    if (columns >= 3) this.DataPoints.Columns.Add(this.ColumnThree);    // string with label for a third data column - not used in the graph
}
if (columns == 4) this.DataPoints.Rows.Add(row[0], double.Parse(row[1]), double.Parse(row[2]), double.Parse(row[3]));
else if (columns == 3) this.DataPoints.Rows.Add(double.Parse(row[0]), double.Parse(row[1]), double.Parse(row[2]));
else this.DataPoints.Rows.Add(double.Parse(row[0]), double.Parse(row[1]));

0 个答案:

没有答案