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
43
Multi-Dimensional Graph Example
posted

 I would like to create a multi-dimensional graph like the example below. My table data is in the format unit, rating and total count

I'm having a hard time trying to work out how to get this effect with webchart. I'm using the databind method.

I have been mucking around with the IRenderLabel class and I can achieve the rating labels on the top of the graph but not in the desired format.

Any help/ideas on how to achieve this would be much appreciated.

Cheers,

Steve

unit rating count

A1 Likely (4)-Serious (1.5)-High 1
A1 Possible (3)-Serious (1.5)-High 60
A1 Possible (3)-Important (1)-Moderate 25
A1 Unlikely (2)-Important (1)-Moderate 2
A1 Possible (3)-Major (4)-Very High 1
A2 Likely (4)-Serious (1.5)-High 1
A2 Possible (3)-Serious (1.5)-High 51
A2 Possible (3)-Important (1)-Moderate 11
A2 Unlikely (2)-Important (1)-Moderate 2

 

Parents
  • 28496
    Suggested Answer
    Offline posted

    basically you need to get the chart data into a format it expects.  here's how i handled this:

                DataTable table = new DataTable();
                table.Columns.Add("unit", typeof(string));
                table.Columns.Add("rating", typeof(string));
                table.Columns.Add("count", typeof(int));
                table.Rows.Add(new object[] { "A1", "Likely (4)-Serious(1.5)-High", 1 });
                table.Rows.Add(new object[] { "A1", "Possible (3)-Serious(1.5)-High", 60 });
                table.Rows.Add(new object[] { "A1", "Possible (3)-Important(1)-Moderate", 25 });
                table.Rows.Add(new object[] { "A1", "Unlikely (2)-Important(1)-Moderate", 2 });
                table.Rows.Add(new object[] { "A1", "Possible (3)-Major(4)-Very High", 1 });
                table.Rows.Add(new object[] { "A2", "Likely (4)-Serious(1.5)-High", 1 });
                table.Rows.Add(new object[] { "A2", "Possible (3)-Serious(1.5)-High", 51 });
                table.Rows.Add(new object[] { "A2", "Possible (3)-Important(1)-Moderate", 11 });
                table.Rows.Add(new object[] { "A2", "Unlikely (2)-Important(1)-Moderate", 2 });

                UltraChart1.ChartType = ChartType.ColumnChart3D;
                UltraChart1.Series.AddRange(this.GetSeriesFromTable(table, "rating", "unit", "count"));
                UltraChart1.Data.DataBind();

           
            private NumericSeries[] GetSeriesFromTable(DataTable table, string seriesNameColumn, string categoryNameColumn, string valueColumn)
            {
                List<NumericSeries> result = new List<NumericSeries>();
                Dictionary<string, NumericSeries> seriesByLabel = new Dictionary<string, NumericSeries>();
               
                StringCollection allCategories = new StringCollection();
                // first create all the series
                foreach (DataRow row in table.Rows)
                {
                    string seriesLabel = row[seriesNameColumn].ToString();
                    NumericSeries currentSeries;
                    if (seriesByLabel.ContainsKey(seriesLabel))
                    {
                        currentSeries = seriesByLabel[seriesLabel];
                    }
                    else
                    {
                        currentSeries = new NumericSeries();
                        currentSeries.Label = seriesLabel;
                        result.Add(currentSeries);
                        seriesByLabel.Add(seriesLabel, currentSeries);
                    }
                    string category = row[categoryNameColumn].ToString();
                    if (!allCategories.Contains(category))
                    {
                        allCategories.Add(category);
                    }
                }
                foreach (NumericSeries series in result)
                {
                    foreach (string category in allCategories)
                    {
                        series.Points.Add(new NumericDataPoint(0.0, category, false));
                    }
                }
                foreach (DataRow row in table.Rows)
                {
                    string seriesLabel = row[seriesNameColumn].ToString();
                    NumericSeries currentSeries = seriesByLabel[seriesLabel];
                    string category = row[categoryNameColumn].ToString();
                    int indexOfCategory = allCategories.IndexOf(category);
                    currentSeries.Points[indexOfCategory].Value = Convert.ToDouble(row[valueColumn]);
                }
                return result.ToArray();
            }

Reply Children
No Data