Search code examples
c#winformsinfragistics

Bingind data to linechart


i have datatable which has 2 columns and 8 rows and the output is like below;

Size     Improvement
--------------------
256       -26.05
512       -646.13
768       -38.96
1024      0
1280      1.13
1536      1.34
1792      1.34
2048      1.34

I want to assign 'Size' column on X-axis and 'Improvement' column on Y-axis and i want to show only improvement column values on line chart.

However when i bind the datatable 'Size' column goes to on 'Y-axis' and X-axis display nothing.

How can i control the columns on axis?


Solution

  • I am not sure if you need UltraChart or UltraDataChart. If you need UltraChart you should use Scatter chart, and not Line chart. Also you will need to add some labels to your data like this:

    var dt = new DataTable();
    dt.Columns.Add("label");
    dt.Columns.Add("Size", typeof(int));
    dt.Columns.Add("Improvement", typeof(double));
    
    dt.Rows.Add(new object[] { "a", 256, -26.05 });
    dt.Rows.Add(new object[] { "b", 512, -646.13 });
    dt.Rows.Add(new object[] { "c", 768, -38.96 });
    dt.Rows.Add(new object[] { "d", 1024, 0 });
    dt.Rows.Add(new object[] { "e", 1280, 1.13 });
    dt.Rows.Add(new object[] { "f", 1536, 1.34 });
    dt.Rows.Add(new object[] { "g", 1792, 1.34 });
    dt.Rows.Add(new object[] { "h", 2048, 1.34 });
    

    Then set the type of your chart to ScatterChart, bind the data and ConnectWithLines property to true like this:

    this.ultraChart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.ScatterChart;
    this.ultraChart1.DataSource = dt;
    this.ultraChart1.DataBind();
    this.ultraChart1.ScatterChart.ConnectWithLines = true;
    

    If you need UltraDataChart you should use ScatterLineSeries as shown in Infragistics online help here - "Scatter Line Series"