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

2 int column DataTable shown by RadChart as 2 bars instead of 1 bar & 1 xAxis

1 Answer 44 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
ilan
Top achievements
Rank 1
ilan asked on 27 Jan 2014, 10:40 AM
Hi, 
I have a SQL DataTable of two integer columns, one represent week-numbers (i.e 201402), and the second represent the actual values (i.e 235).
When I'm trying to show the data by RadChart object it shows the two columns as two bars, for each week-number. like this:
values & week-number as 2 yAxises,
week-number as xAxis.  

201402
|     235
|      |
|      |
201402

What I really want is only one bar (the value from the second column) for each week-number (from the first column):
values as yAxis,
week-number as xAxis.  

235
  |
  |
201402  

When I use another datatable, with the first column containing strings, the chart is ok.
So a guess is that I need to block it from binding the first column somehow. tried million things already, none succeeded.

Thank you,
Milky.

1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 30 Jan 2014, 08:22 AM
Hi Milky,

This behavior usually happens when you initially bind the chart and then configure series' DataYColumn and x-axis' DataLabelsColumn properties. For example:
ASPX:
<telerik:RadChart ID="RadChart1" runat="server" Width="600" Height="400">
</telerik:RadChart>
C#:
protected void Page_Load(object sender, EventArgs e)
{
    RadChart1.DataSource = GetData();
    RadChart1.DataBind();
    ChartSeries cs1 = new ChartSeries();
    cs1.DataYColumn = "Num";
    RadChart1.Series.Add(cs1);
    RadChart1.PlotArea.XAxis.DataLabelsColumn = "GroupBy1";
}

In order to avoid this unwanted behavior you must configure series and axes prior to binding. For example:
ASPX:
<telerik:RadChart ID="RadChart1" runat="server" Width="600" Height="400">
</telerik:RadChart>
C#:
protected void Page_Load(object sender, EventArgs e)
{
    ChartSeries cs1 = new ChartSeries();
    cs1.DataYColumn = "Num";
    RadChart1.Series.Add(cs1);
    RadChart1.PlotArea.XAxis.DataLabelsColumn = "GroupBy1";
    RadChart1.DataSource = GetData();
    RadChart1.DataBind();
}
 
protected DataTable GetData()
{
    DataTable dt = new DataTable();
 
    dt.Columns.Add("ID");
    dt.Columns.Add("GroupBy1");
    dt.Columns.Add("Num");
 
    dt.Rows.Add(1, 201402, 235);
    dt.Rows.Add(2, 201403, 219);
    dt.Rows.Add(3, 201404, 208);
    dt.Rows.Add(4, 201405, 15);
 
    return dt;
}

I have also attached the runnable VS example to this post. If the above step, however, is not helpful, could you please try to reproduce the issue with the attached VS example and then send it back to us, so that we can make an investigation locally?


Regards,
Danail Vasilev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Chart (Obsolete)
Asked by
ilan
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or