This is a migrated thread and some comments may be shown as answers.

Issue with Line Chart

5 Answers 97 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sergio
Top achievements
Rank 1
Sergio asked on 22 Feb 2012, 09:49 AM
Hello,

I have a problem when I try to show some data on a Line Chart.

I have attached one image with both Data and Line Chart.

As you can see, the green line is not correct because its three values are located on the first three points (Mar'11, May'11 and Jul'11), and must be located on second, third, an sixth respectively (May'11 Jul'11 and Ene'12) as it is shown on Data Table.

The SQL source for this Chart is this:

ES00000120S9     
09/03/2011 0:00:00     
Mar'11     
36,9388000000        
20/02/2012
ES00000120S9 09/05/2011 0:00:00 May'11 38,3738000000 20/02/2012
ES00000120S9 11/07/2011 0:00:00 Jul'11 41,0802000000 20/02/2012
ES00000120S9 09/09/2011 0:00:00 Sep'11 47,0580000000 20/02/2012
ES00000120S9 09/11/2011 0:00:00 Nov'11 51,5185000000 21/02/2012
ES00000120S9 09/01/2012 0:00:00 Ene'12 52,7473000000 21/02/2012
ES00000121J6 09/03/2011 0:00:00 Mar'11 94,4507000000 20/02/2012
ES00000121J6 09/05/2011 0:00:00 May'11 94,7643000000 20/02/2012
ES00000121J6 11/07/2011 0:00:00 Jul'11 95,7689000000 20/02/2012
ES00000121J6 09/09/2011 0:00:00 Sep'11 97,2266000000 20/02/2012
ES00000121J6 09/11/2011 0:00:00 Nov'11 97,1023000000 21/02/2012
ES00000121J6 09/01/2012 0:00:00 Ene'12 97,4383000000 21/02/2012
ES00000121T5 09/05/2011 0:00:00 May'11 100,0459000000 20/02/2012
ES00000121T5 11/07/2011 0:00:00 Jul'11 100,4433000000 20/02/2012
ES00000121T5 09/01/2012 0:00:00 Ene'12 383,3258000000 21/02/2012

The last three values are located on Mar'11, May'11 and Jul'11 on chart.

I don't know how to fix it.

Is there any solution?

Thank you very much.

5 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 22 Feb 2012, 10:23 AM
Do you bind the X values? Because if you don't, the chart automatically assigns consequential numbers (1, 2, 3, ...) and this is why every series will begin from 0 and will not respect the empty values. 

From my experience with charts, in almost any case it's easier to programmatically create it (create the series and add the items). If you do it programmatically you will have total control over it. 

Look at this:
http://www.telerik.com/help/reporting/buildingprogrammaticcreate2.html 
0
Sergio
Top achievements
Rank 1
answered on 22 Feb 2012, 10:57 AM
Thanks for your prompt response.

How I can bind X Axis from Report designer?

Now I have bound DataGroupColumn and X Axis' DataLabelsColumn but I don't find any other bind property.

Thank you.
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 22 Feb 2012, 02:57 PM
Since you have date for X values, I am not really sure if you can do that directly. 
The documentations says: "To add dates to an axis or chart item, values must be converted to OleAutomation types.  Use the 
DateTime ToOADate() function for this purpose." source: http://www.telerik.com/help/reporting/understandingtypesgantt.html 

From my experience, I believe that the only way to accomplish your goal would be to programmatically create the chart. 
0
Sergio
Top achievements
Rank 1
answered on 22 Feb 2012, 06:03 PM
Now I had change the select to obtain this table

ES00000120S9       
1        
Mar'11     
36,9388000000
ES00000120S9 2 May'11 38,3738000000
ES00000120S9 3 Jul'11 41,0802000000
ES00000120S9 4 Sep'11 47,0580000000
ES00000120S9 5 Nov'11 51,5185000000
ES00000120S9 6 Ene'12 52,7473000000
ES00000121J6 1 Mar'11 94,4507000000
ES00000121J6 2 May'11 94,7643000000
ES00000121J6 3 Jul'11 95,7689000000
ES00000121J6 4 Sep'11 97,2266000000
ES00000121J6 5 Nov'11 97,1023000000
ES00000121J6 6 Ene'12 97,4383000000
ES00000121T5 2 May'11 100,0459000000
ES00000121T5 3 Jul'11 100,4433000000
ES00000121T5 6 Ene'12 383,3258000000

Dates has been changed by the X Axis' position DataLabelsColumn is the third one and DataGroupColumn is the first one.
Although second column is filled with numbers and no dates. The chart is giving the same incorrect output.

I have no time to make the chart programatically (my only solution is adding a image from a chart developed on other framework that works perfectly).

Is there any other possible solution excluding programatically one?

Thank you very much.
0
Elian
Telerik team
answered on 27 Feb 2012, 02:43 PM
Hi Sergio,

This is a limitation of the current chart control. As Hadib said, the layout you need, can be achieved only programmatically. Here's a sample code of how to programmatically create series and items using DataTable and SqlDataAdapter:

//retrieves the data from the database
public DataTable GetData()
{  
    string connectionString = "Data Source...";
    string selectString = "SELECT...";
    SqlDataAdapter sqlAdapter = new SqlDataAdapter(selectString, connectionString);
    DataSet ds = new DataSet();
    sqlAdapter.Fill(ds);
    foreach(var row in ds.Tables[0].Rows)
    {
        ...
    }
    return ds.Tables[0];   
}
 
 private void chart1_NeedDataSource(object sender, EventArgs e)
{
    var dataTable = GetData(); 
 
    //chart is the object from the report definition
    //create the series for the chart
    chart1.Series.Add(new Charting.ChartSeries("Series1"));
    chart1.Series.Add(new Charting.ChartSeries("Series2"));
     
    foreach(DataRow row in dataTable)
    {
         var newItem = new Charting.ChartSeriesItem(x, y);
         //add the items to the corresponding series
         if(...)
         {
            chart1.Series[0].Items.Add(newItem);
         }
         else       
         {
            chart1.Series[1].Items.Add(newItem);
         }
    }
}

Here are a couple of links that further discuss the matter:
Creating Chart Programmatically 
Creating Chart Programmatically (advanced)

Greetings,
Elian
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
Sergio
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Sergio
Top achievements
Rank 1
Elian
Telerik team
Share this question
or