This is a migrated thread and some comments may be shown as answers.

Bar Chart

1 Answer 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bader
Top achievements
Rank 1
Bader asked on 24 Jul 2011, 10:52 AM
Hello,

I have a problem with buiding a bar chart as it shown in the attached image.
I used the code which was supported in the thread http://www.telerik.com/community/forums/reporting/telerik-reporting/setting-bar-chart-bar-color.aspx. But As you can see in the attched image I need to set two bars (maybe more) for each X value.

Plaese, I need your help,
It is appreciated to send me a modified code.

Regards,
Bader

1 Answer, 1 is accepted

Sort by
0
Bader
Top achievements
Rank 1
answered on 24 Jul 2011, 01:39 PM
Hello All,

I found the solutions,
You have to use the chart attributes as it is shown in the ASP.NET Ajax demo http://demos.telerik.com/aspnet-ajax/chart/examples/skinning/bars/defaultcs.aspx.

private void chart2_NeedDataSource(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add("RID", typeof(int));
            table.Columns.Add("Value", typeof(double));
            table.Columns.Add("Color", typeof(Color));
 
            table.Rows.Add(new object[] {1, 1, Color.Red });
            table.Rows.Add(new object[] {2, 2, Color.Green });
            table.Rows.Add(new object[] {3, 1, Color.Blue });
            table.Rows.Add(new object[] {4, 3, Color.Yellow });
            table.Rows.Add(new object[] {5, 2, Color.Black });
 
            table.Rows.Add(new object[] {6, 3, Color.Red });
            table.Rows.Add(new object[] {7, 1, Color.Green });
            table.Rows.Add(new object[] {8, 3, Color.Blue });
            table.Rows.Add(new object[] {9, 1, Color.Yellow });
            table.Rows.Add(new object[] {10, 2, Color.Black });
 
            Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender;
            Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition;
             
            chartDef.PlotArea.XAxis.MaxValue = 100;
            chartDef.PlotArea.XAxis.MinValue = 1;
            chartDef.PlotArea.XAxis.Step = 1;
 
            chartDef.PlotArea.YAxis.MaxValue = 18;
            chartDef.PlotArea.YAxis.AxisMode = ChartYAxisMode.Extended;
            chartDef.PlotArea.YAxis.Step = 0.5;
 
            chartDef.PlotArea.YAxis2.MaxValue = 18;
            chartDef.PlotArea.YAxis2.MinValue = 1;
            chartDef.PlotArea.YAxis2.Step = 1;
 
            Telerik.Reporting.Charting.ChartSeries series = new Telerik.Reporting.Charting.ChartSeries();
            series.Name = "SeriesA 1";
 
            Telerik.Reporting.Charting.ChartSeries series1 = new Telerik.Reporting.Charting.ChartSeries();
            series1.Name = "SeriesA 2";
             
            
 
            foreach (DataRowView rowView in table.DefaultView)
            {
                int num = Convert.ToInt32(rowView["RID"]);
 
                if (num <= 5)
                {
                    Telerik.Reporting.Charting.ChartSeriesItem seriesItem = new Telerik.Reporting.Charting.ChartSeriesItem();
                    seriesItem.YValue = (double)rowView["Value"];
                    seriesItem.Name = "Series " + num.ToString();
                    seriesItem.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                    seriesItem.Appearance.FillStyle.MainColor = (Color)rowView["Color"];
                    series.AddItem(seriesItem);
                }
                else
                {
                    Telerik.Reporting.Charting.ChartSeriesItem seriesItem1 = new Telerik.Reporting.Charting.ChartSeriesItem();
                    seriesItem1.YValue = (double)rowView["Value"];
                    seriesItem1.Name = "Series " + num.ToString();
                    seriesItem1.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                    seriesItem1.Appearance.FillStyle.MainColor = (Color)rowView["Color"];
                    series1.AddItem(seriesItem1);
                }
            }
 
            
            chartDef.Series.Clear();
            chartDef.Series.Add(series);
            chartDef.Series.Add(series1);
        }


Regards,
Bader

Tags
General Discussions
Asked by
Bader
Top achievements
Rank 1
Answers by
Bader
Top achievements
Rank 1
Share this question
or