1

I am plotting a Microsoft System.Web.UI.DataVisualization.Charting.Chart with three series (two columns and an overlaying line). It appears that the y axis upper bound is auto calculated based on the data range in the first series added to the chart. Subsequently any series does not get rendered when its y value is greater than the first series y value. In this instance I would like it to use the maximum value from any series.

The series are added to the chart via a generic method:

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);
            }

If I reverse the order the series are added to the chart then the plot area is correct, however the line series sits behind the columns.

Any ideas? Thanks.

1 Answers1

0

I'm assuming you have a single chart area that you are adding the series' to? If so, you can modify the maximum value of the Y axis that belongs to that chart area. It would be something like this:

// put this block above your foreach loop
double maxval = 100; // <-- put your maximum value here.
chart.ChartAreas[0].AxisY.Maximum = maxval;

Using LINQ, you can easily find the maximum value inside all of your series then set that discovered max value as the AxisY.Maximum.

Bill Sambrone
  • 4,334
  • 4
  • 48
  • 70
  • Thanks, I had tried the same thing already but your answer confirmed I wasn't going mad (been a long day). I needed to add an additional buffer to the maximum value in order for it to render. My maximum value was 9,310,836 but setting that chopped off the top of the columns and most of the line. Upping it to 12,000,000 worked like a charm. Tip, you can get the max value DataPoint in a series using: Series.Points.FindMaxByValue("Y1"); – over the hill Aug 13 '13 at 20:11