1. How do I set ChartSeriesItem.Label.Appearance.Visible = false
after binding a stackedbar-chart's datasource to a DataTable in the NeedDataSource method?
2. If this cannot be accomplished, I assume I would have to build the ChartSeries programmatically. Can you direct me to code specifically geared towards programmatically building stackedbar charts? (The goal is an X-Axis with a date-label and stacked values representing different count-values. The legend should be the DataTable column-names.)
The DataTable looks like this (the column-names are actually error-numbers from an external system):
MDate 10230 13456 23432
2011-01 4 1 1
2011-02 0 2 2
2011-03 2 0 0
The chart should look like this:
6|-G--|
5|----| |----| ¤ 10230(red)
4| B | | G | ¤ 13456(blue)
3|----| |----| ¤ 23432(green)
2| R | | B | |----|
1|____|__|____|__|__R_|_____
2011 2011 2011
-01 -02 -03
Hope you understand my question. The chart works fine with databinding but I would really like to take away the text on the bars and just leave the color with a legend instead.
Thanks for any assistance you can offer.
5 Answers, 1 is accepted
Check out the following code snippet that illustrates how to create a similar stacked bar chart:
public partial class StackCharts : Telerik.Reporting.Report { public StackCharts() { InitializeComponent(); var chart = NewChart(); this.detail.Items.Add(chart); } private Telerik.Reporting.Chart NewChart() { var chart = new Telerik.Reporting.Chart(); chart.BitmapResolution = 96F; chart.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf; chart.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(0.32), Telerik.Reporting.Drawing.Unit.Cm(1.8)); chart.Name = "progchart1"; chart.PlotArea.EmptySeriesMessage.Appearance.Visible = true; chart.PlotArea.EmptySeriesMessage.Visible = true; chart.PlotArea.XAxis.AxisLabel.Visible = true; chart.PlotArea.YAxis.AxisLabel.Visible = true; chart.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(9.6), Telerik.Reporting.Drawing.Unit.Cm(6.1)); chart.ChartTitle.TextBlock.Text = "My chart"; chart.ChartTitle.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Blue; // Define chart series var chartSeries = NewChartSeries("52561", Color.Red, 80, 40, 30); var chartSeries2 = NewChartSeries("22233", Color.Green, 30, 90, 40); var chartSeries3 = NewChartSeries("45666", Color.Blue, 20, 40, 70); // set the plot area gradient background fill chart.PlotArea.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Gradient; chart.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.FromArgb(65, 201, 254); chart.PlotArea.Appearance.FillStyle.SecondColor = System.Drawing.Color.FromArgb(0, 107, 186); // Set text and line for X axis chart.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Months"; chart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red; chart.PlotArea.XAxis.Appearance.Width = 3; chart.PlotArea.XAxis.Appearance.Color = System.Drawing.Color.Red; chart.PlotArea.XAxis.AutoScale = false; chart.PlotArea.XAxis.AddItem("2011-01"); chart.PlotArea.XAxis.AddItem("2011-02"); chart.PlotArea.XAxis.AddItem("2011-03"); // Set text and line for Y axis chart.PlotArea.YAxis.AxisLabel.TextBlock.Text = "%"; chart.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red; chart.PlotArea.YAxis.Appearance.Width = 3; chart.PlotArea.YAxis.Appearance.Color = System.Drawing.Color.Red; // Add the series to the chart, chart to page. chart.Series.Add(chartSeries); chart.Series.Add(chartSeries2); chart.Series.Add(chartSeries3); return chart; } private static ChartSeries NewChartSeries(string name, Color color, params int[] values) { // Define chart series var chartSeries = new ChartSeries(); chartSeries.Appearance.LabelAppearance.Visible = false; chartSeries.Name = String.Format("{0}({1})", name, color.ToKnownColor()); chartSeries.Type = ChartSeriesType.StackedBar; chartSeries.Appearance.FillStyle.MainColor =color; chartSeries.Appearance.FillStyle.FillType = Charting.Styles.FillType.Solid; // Define the items in the series foreach (var value in values) { chartSeries.AddItem(value); } return chartSeries; } }Peter
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
You rock!!!! Thanks.
I do find it strange that one minor change to a Chart (generated from a bound datasource) requires a complete re-think and a substantial amount of code. Any chance of a change in coming releases?
The Chart report item uses the same engine as RadChart for ASP.NET AJAX which is ASP.NET control and not meant to be used in our product. That is why some customizations that are normally handled through chart events in the control, have no alternative on our end except creating it entirely with code.
Anyway we plan to work on a native chart item for the report product and hope to have a first version sooner than later (cannot engage with time frame).
Thank you for the understanding.
All the best,
Steve
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
I am creating a bar chart. The datasource is a datatable having values. The X-Axis has the date and the Y-Axis has values. When done this way the Datapoints are being displayed on top of each bar. I do not want to display the Datapoint value. How do I disable this? I had check the example they had given "chartSeries.Appearance.LabelAppearance.Visible = false;"(doesnot support). Is there any way the I can remove the datapoints.
The other is that if i have 100 values i do not need to display 100 dates may be 5 or 6 (MaxItemCount) it would be like 5 dates and 100 values displayed. MaxItemCount does not respond properly it displays all dates.
I am using visual studio 2010, Telerik Reporting (licensed -TV446243)
Regards,
Saravanan.R
Creating the series manually is the only way to solve this issue. As to the dates, you need to adjust the XAxis min/max values, so that the range value matches your data. Here's a sample code achieving that:
//adjust the y-axischart.PlotArea.XAxis.AutoScale = false;chart.PlotArea.XAxis.MinValue = startDate.ToOADate();chart.PlotArea.XAxis.MaxValue = endDate.ToOADate();//this sets the format for the labels on the axischart.PlotArea.XAxis.Appearance.ValueFormat = ChartValueFormat.ShortDate;//If your date range is big, widen the step to avoid overcrowdingchart.PlotArea.XAxis.Step = 10;Higher value of the Step property will reduce the labels on the Axis.
Kind regards,Elian
the Telerik team