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
185
Column Chart
posted

Hello there

I have  a quick question about columnchart

I have a dataTable with the following columns

- YEAR

- TYPE

- VAL1

-VAL2

-VAL3

a table looks like that :

2009   typeA   10   20   30

2010   typeA   11   22   33

2011   typeA   13   24   35

2012   typeB   17   50   30

2013   typeB   10   40   30

2014   typeB   20   20   38

 

How do I setup my column Chart to display year by year two columns one for typeA the other for type B displaying the value of VAL1 for each  column (I don't need the other ones)

So basically I need

- columnset based on the value of a row (in my case the value of  Type) instead of  columnset based on the columns name

- display the value of one column (in my case VAL1) and hide all the others ones.

Is that possible to do so without recreating an other table with my values

 

 

 

  • 28496
    Suggested Answer
    Offline posted

    the column chart's data requirements are outlined here: http://help.infragistics.com/Help/NetAdvantage/WinForms/2009.1/CLR2.0/html/Chart_Working_with_2D_Column_Chart_Data.html

    the data needs to be in a format described on that page.  here's one way you can process your table into NumericSeries:

     

      private void Form1_Load(object sender, EventArgs e)
            {
                DataTable table = new DataTable();
                table.Columns.Add("YEAR", typeof(string));
                table.Columns.Add("TYPE", typeof(string));
                table.Columns.Add("VAL1", typeof(double));
                table.Columns.Add("VAL2", typeof(double));
                table.Columns.Add("VAL3", typeof(double));
                table.Rows.Add(new object[] { "2009", "typeA", 10, 20, 30 });
                table.Rows.Add(new object[] { "2010", "typeA", 11, 22, 33 });
                table.Rows.Add(new object[] { "2011", "typeA", 13, 24, 35 });
                table.Rows.Add(new object[] { "2012", "typeB", 17, 50, 30 });
                table.Rows.Add(new object[] { "2013", "typeB", 10, 40, 30 });
                table.Rows.Add(new object[] { "2014", "typeB", 20, 20, 38 });

                NumericSeries[] tableAsSeries = this.ProcessTableIntoSeries(table);
                foreach (NumericSeries series in tableAsSeries)
                {
                    this.ultraChart1.Series.Add(series);
                }
      
            }
            private NumericSeries[] ProcessTableIntoSeries(DataTable table)
            {
                Dictionary<string, NumericSeries> yearlySeries = new Dictionary<string, NumericSeries>();
                foreach (DataRow row in table.Rows)
                {
                    this.ProcessRow(yearlySeries, row);
                }
                return yearlySeries.Values.ToArray();
            }
            private void ProcessRow(Dictionary<string, NumericSeries> yearlySeries, DataRow row)
            {
                string year = row["YEAR"].ToString();
                string itemLabel = row["TYPE"].ToString();
                if (!yearlySeries.ContainsKey(year))
                {
                    yearlySeries.Add(year, new NumericSeries());
                    yearlySeries[year].Label = year;
                }
                double value = (double)row["VAL1"];
                yearlySeries[year].Points.Add(new NumericDataPoint(value, itemLabel, false));
            }