Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
225
How to bind chart to DataTable or SQLDataSource
posted

Hi,

I have an UltraChart control. It looks like this:

<igchart:UltraChart ID="UltraChart1" runat="server" EmptyChartText="Data Not Available" Version="10.2">
</igchart:UltraChart>

In the code behind I have this:

protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("label", typeof(string));
            dt.Columns.Add("cost", typeof(double));
            dt.Rows.Add("item 1", 29);
            dt.Rows.Add("item 2", 33);
            dt.Rows.Add("item 3", 28);
            dt.Rows.Add("item 4", 35);

            NumericSeries series = new NumericSeries();
            series.Data.DataSource = dt;
            series.Data.LabelColumn = "label";
            series.Data.ValueColumn = "cost";
            series.DataBind();
            UltraChart1.Series.Add(series);
            UltraChart1.Data.DataBind();
        }

The result is a chart with some values. Great!

---------

So what I have done is create a new Composite Chart using the wizard. I called it UltraChart2. I added all the Areas, Axis, Data, Chart Layers and Legends. I got the chart looking exacly the way I like it. I'm not going to put the code here unless you ask for it because it is like 250 lines long.

Now all I want to do is replace the current data that I added when I went through the wizard to some custom data. So once again, I put this in the code behind:

protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("label", typeof(string));
            dt.Columns.Add("cost", typeof(double));
            dt.Rows.Add("item 1", 29);
            dt.Rows.Add("item 2", 33);
            dt.Rows.Add("item 3", 28);
            dt.Rows.Add("item 4", 35);

            NumericSeries series = new NumericSeries();
            series.Data.DataSource = dt;
            series.Data.LabelColumn = "label";
            series.Data.ValueColumn = "cost";
            series.DataBind();
            UltraChart2.Series.Add(series);
            UltraChart2.Data.DataBind();
        }

The result is the chart with exacly the same data that I added in the wizard. If I delete this data, I get a blank chart.

This should be a simple process but I'm obviously missing something vital. Can you fill me in?

Parents
No Data
Reply
  • 12004
    posted

    Hello,

    I ran the provided code snippet and it looks to be correctly displaying the chart when databinding to the DataTable with custom data.

    Is the issue that you are having is that you're unable to display the chart correctly with using the custom data in the code provided?

    For samples you can provide an attachment to the thread or send it to support@infragistics.com and I'll take a look at it further. When sending it in email you can provide the forum thread link url.

    Let me know if you have any questions with this matter. Thank you.

Children