5

I have been trying to render a line chart using the basic asp.net Chart class. Whatever I do, it always renders a column chart. Here is my code where I am binding a datatable to the chart.

var IEtable = (table as System.ComponentModel.IListSource).GetList();

var chart = new Chart(width: 1000, height: 1000)
    .AddSeries(chartType: "Line").AddLegend("Key")
    .AddTitle("Time Series Metric")
    .DataBindCrossTable(IEtable, "Key", "Date", "Value");

Can anyone please help? I am been breaking my head with this thing since more than 12 hours now.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
Kinnary Jangla
  • 123
  • 1
  • 6
  • Looks like someone deleted my last question. Maybe due to the previous arguments. I'll post it again in case anyone has an idea. – Kinnary Jangla Nov 01 '13 at 19:56
  • lot of links that have examples of line charts are basically setting the charttype to line. I have tried doing that as well like in my code above. But it didnt help. Is there a way to work around this? Or I'm starting to wonder if asp.net has a constraint that it only renders a column chart when you bind a datatable to a chart. – Kinnary Jangla Nov 01 '13 at 19:58

1 Answers1

0

I'm building my charts slightly differently - perhaps because I'm building mine in MVC pages? Anyway, I'm still using the MS Chart stuff - http://msdn.microsoft.com/en-us/library/ee410579.ASPX

I create my chart:

var chart = new Chart();
chart.Width = 900;
chart.Height = 500;
...lots more options...

then add my series one at a time....

chart.Series.Add(CreateDataSeries(id, "GI Lower", null, null, GetGILowerDataPoints));
chart.Series.Add(CreateDataSeries(id, "GI Upper", null, null, GetGIUpperDataPoints));

where CreateDataSeries sets the chart type like this:

Series seriesDetail = new Series();
seriesDetail.ChartType = SeriesChartType.Spline;
...
return seriesDetail;

Does that help at all?

Dave R
  • 1,626
  • 19
  • 28