我正在使用三个系列(两列和一条重叠线)绘制Microsoft System.Web.UI.DataVisualization.Charting.Chart。看来y轴上限是根据添加到图表中的第一个系列中的数据范围自动计算的。随后,当y值大于第一个y系列值时,任何系列都不会被渲染。在这种情况下,我希望它使用任何系列中的最大值。
系列通过通用方法添加到图表中:
foreach (var s in model.Series)
{
var chartSeries = new Series(s.Title);
chartSeries.ChartType = s.Type;
chartSeries.Color = s.DrawColour;
// add the data to the series
foreach (DataRow row in data.Tables[0].Rows)
{
chartSeries.Points.AddXY(row[model.XAxis.DataColumnName], row[s.ColumnName]);
}
// does the series name come from a column? if not use the plain text. if the column has a caption use it, otherwise the column name.
chartSeries.Name = data.Tables[0].Columns.Contains(s.Title) ? String.IsNullOrEmpty(data.Tables[0].Columns[s.Title].Caption) ? data.Tables[0].Columns[s.Title].Caption : data.Tables[0].Columns[s.Title].ColumnName : s.Title;
chart.Series.Add(chartSeries);
}
如果我颠倒顺序,系列会被添加到图表中,那么绘图区域是正确的,但是系列位于列的后面。
有什么想法吗? 感谢。
答案 0 :(得分:0)
我假设你有一个图表区域,你要添加系列'?如果是这样,您可以修改属于该图表区域的Y轴的最大值。它会是这样的:
// put this block above your foreach loop
double maxval = 100; // <-- put your maximum value here.
chart.ChartAreas[0].AxisY.Maximum = maxval;
使用LINQ,您可以轻松找到所有系列中的最大值,然后将发现的最大值设置为AxisY.Maximum。