Microsoft System.Web.UI.DataVisualization.Charting.Chart

本文关键字:Charting Chart DataVisualization UI System Web Microsoft | 更新日期: 2023-09-27 18:27:35

我正在绘制一个包含三个系列(两列和一条重叠线)的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);
            }

如果我颠倒序列添加到图表中的顺序,则绘图区域是正确的,但是线序列位于列后面。

有什么想法吗?谢谢

Microsoft System.Web.UI.DataVisualization.Charting.Chart

我假设您有一个单独的图表区域,要将系列添加到其中?如果是,则可以修改属于该图表区域的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.