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
115
Sorting by Column with UltraChart
posted

Hi,

I'm looking for a way to sort data by a column as it is displayed in a BarChart.

At present I have the following:

DataTable table;
table.Columns.Add("Key", typeof(int));
table.Columns.Add("Labels", typeof(string)); // the Key in string format
table.Columns.Add("Value1", typeof(double));
table.Columns.Add("Value2", typeof(double));

// ...Populate datatable...

chart.DataSource = table;
chart.DataBind();

      foreach (DataColumn col in table.Columns)
      {
        if(col.ColumnName.Equals("Key"))
        {
          chart.Data.IncludeColumn(col,false);
        }
        else
        {
          chart.Data.IncludeColumn(col, true);
        }
      }

At present the labels are appear (in no useful order) along one of the axes, and the "Value1" and "Value2" are shown as bars for each label.

I'd like to sort the table by "Key" and then have that reordering reflected in the order of the labels on the axis of the chart.

Does anyone know how to do this? I am using v8.2

Many thanks,
Luke

  • 115
    posted

    Note that I have tried:

    1)
    table.DefaultView.Sort = "Key"

    2)
    table.DefaultView.Sort = "Key"
    chart.DataSource = table.DefaultView

    3)
    DataView dv = new DataView(table)
    dv.Sort = "Key"
    chart.DataSource = dv

    Something I didn't point out first time round: the data in the table continues to change after it is created, so I'd rather not have to recreate the table each time there is an update to its content!

    Thanks again,
    Luke