I'm trying to achieve something with the UltraWebChart but just can't seem to get the data to appear as I need.
I have a DataTable with 3 columns as shown below:
Year Product SalesCount
France Product1 3
France Product2 6
France Product3 9
Itally Product5 7
Itally Product6 3
Itally Product7 8
Spain Product10 7
Spain Product11 12
Spain Product12 9
What I'm trying to achieve is a column chart with the data grouped into Country and separated by the products. VERY IMPORTANT is that the products for each country are different.
I have been trying to do it in a lots of different way but I was alaways unsuccesful.
Thanks in advance for any advise.
I am sure you guys are very busy, but I would greatly appreciate some help on this problem. I am really losing my hairs trying to figure it out
Thanks in advance
Any idea please? I am still blocked with this problem.
thanks in advance
Sorry for the delay and thanks for bumping this post. The chart itself isn't really capable of doing its own grouping, so it has to be done manually before the data is fed into the chart. Here's one way of doing this.
Create a series for each country and populate the series' datapoints from the other 2 columns.
Here's a code snippet:private void Page_Load(object sender, EventArgs e){ DataTable dt = new DataTable(); dt.Columns.Add("country", typeof (string)); dt.Columns.Add("product", typeof (string)); dt.Columns.Add("count", typeof (int)); dt.Rows.Add(new object[] {"France", "Product1", 3}); dt.Rows.Add(new object[] {"France", "Product2", 6}); dt.Rows.Add(new object[] {"France", "Product3", 9});
dt.Rows.Add(new object[] {"Italy", "Product5", 7}); dt.Rows.Add(new object[] {"Italy", "Product6", 3}); dt.Rows.Add(new object[] {"Italy", "Product7", 8});
dt.Rows.Add(new object[] {"Spain", "Product10", 7}); dt.Rows.Add(new object[] {"Spain", "Product11", 12}); dt.Rows.Add(new object[] {"Spain", "Product12", 9});
UltraChart1.ChartType = ChartType.ColumnChart;
Dictionary<string, NumericSeries> seriesList = new Dictionary<string, NumericSeries>();
foreach (DataRow row in dt.Rows) { string countryName = (string) row["country"]; if (!seriesList.ContainsKey(countryName)) { NumericSeries series = new NumericSeries(); series.Label = countryName; series.Points.Add(new NumericDataPoint((int) row["count"], (string) row["product"], false)); seriesList.Add(countryName, series); } else { NumericSeries series = seriesList[countryName]; series.Points.Add(new NumericDataPoint((int) row["count"], (string) row["product"], false)); } }
foreach (KeyValuePair<string, NumericSeries> dictionaryEntry in seriesList) { UltraChart1.Series.Add(dictionaryEntry.Value); }}