0

Chart doesn't display and no any error. Can Any one suggest me why my chart is not plot and whats wrong going on here.

Chart1.Titles.Add("Case");
Chart1.DataSource = dt;
Series s = new Series();
s.XValueMember = Convert.ToString(x);
s.YValueMembers = Convert.ToString(y);
Chart1.DataBind();
Maddy
  • 4,525
  • 4
  • 33
  • 53
Mehul Lad
  • 9
  • 4
  • Sounds like Chart1.Series hasn't been initialised. – Steve Aug 22 '17 at 10:35
  • It would seem that you haven't added any series to your chart. Can you show us more code, particularly where you create the chart object and add the series? – Diado Aug 22 '17 at 10:35
  • Possible duplicate of [What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?](https://stackoverflow.com/questions/20940979/what-is-an-indexoutofrangeexception-argumentoutofrangeexception-and-how-do-i-f) – Rohit416 Aug 22 '17 at 10:36
  • 1
    You seem to be changing questions here - in your original post you said you got an index out of range error - now you say you get no error. If this is a new problem then you should create a new question, not modify the original. – PaulF Aug 22 '17 at 10:55

2 Answers2

0

what you're missing here is adding your newly creates series to chart series collection.

Chart1.Titles.Add("Case");
Chart1.DataSource = dt;
Series s = new Series();
s.XValueMember = Convert.ToString(x);
s.YValueMembers = Convert.ToString(y);
//one line that you're missing
Chart1.Series.Add(s);
Chart1.DataBind();
Nino
  • 6,931
  • 2
  • 27
  • 42
0

First thing you should set chart properties.

Step 1: Go to Chart properties then click on Series.

enter image description here

Step 2 : Change the name of Series. Here, I set the name to Case. We can also change the ChartType

enter image description here

Change your code as follows :

    chart1.DataSource = ds;  
    //set the member of the chart data source used to data bind to the X-values of the series  
    chart1.Series["Case"].XValueMember = Convert.ToString(x);  
    //set the member columns of the chart data source used to data bind to the X-values of the series  
    chart1.Series["Case"].YValueMembers = Convert.ToString(y);  
    chart1.Titles.Add("Case");