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

How to Populate Series, SeriesItem with differnt colors and X axis label programetically

3 Answers 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sridhar Bolisetti
Top achievements
Rank 1
Sridhar Bolisetti asked on 28 Sep 2009, 05:51 AM
Hi,

Since Telerik chart presently not supporting changing series item colors at run when datasource is set, I populated the series and series items with colors at run time with out data source.

Problem: Not able to set X axis labels. The following is the code I have written.

Please help me regarding this.



public static void FillAvgGraph(Telerik.Reporting.Processing.Chart chart, List<AvgPercentGraph> list)
        {
           
            Chart definition =(Chart) chart.ItemDefinition;
            //chart.DataSource = list;
            ChartSeries series = new ChartSeries();
            series.Name = "Percent";
            //series.Type = ChartSeriesType.StackedBar100;
            series.DataYColumn = "Percent";
            definition.Legend.Appearance.Position.AlignedPosition = Telerik.Reporting.Charting.Styles.AlignedPositions.Bottom;
            ChartAxisItemsCollection labels=new ChartAxisItemsCollection();
            int index = 0;
            foreach (AvgPercentGraph data in list)
            {
                ChartSeriesItem seriesItem = new ChartSeriesItem();
                seriesItem.Name = data.Name;
                seriesItem.YValue = (double)data.Percent;
                seriesItem.Label.TextBlock.Appearance.FillStyle.MainColor = Color.Black;
                seriesItem.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                if(data.Percent < 58)seriesItem.Appearance.FillStyle.MainColor = Color.Red;
                else if (data.Percent > 58 && data.Percent < 76) seriesItem.Appearance.FillStyle.MainColor = Color.Yellow;
                else if (data.Percent > 76 && data.Percent <= 100) seriesItem.Appearance.FillStyle.MainColor = Color.Green;
                series.AddItem(seriesItem);
                ChartAxisItem item = new ChartAxisItem(data.Name);
                labels.Add(item);
                
                
            }
           
            series.DefaultLabelValue = "#Y" + "%";
            
            // series.Appearance.LabelAppearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
            // series.Appearance.LabelAppearance.FillStyle.MainColor = Color.Red;
            definition.Series.Clear();
            definition.Series.Add(series);
           // definition.Series[0].PlotArea.XAxis.DataLabelsColumn = "Name";
           
              definition.Series[0].PlotArea.YAxis.AddRange(0,100,20);
              definition.PlotArea.XAxis.Items.AddRange(labels.ToArray());
            
           

        }

3 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 28 Sep 2009, 11:46 AM
Hello Sridhar,

You can create and customize the chart entirely in the NeedDataSouce event of the Chart report item, avoiding the need to set the DataSource property i.e. bind the chart manually. You can see similar example in this forum thread.
As for your current code, there is no need for a local variable labels - you can add the items to the XAxis collection directly. Have you tried setting AutoScale and AutoShrink properties to false to see if that makes a difference?

Regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sridhar Bolisetti
Top achievements
Rank 1
answered on 30 Sep 2009, 01:45 PM
Hi,

Thanks,

X axis labels are displaying after setting AutoScale and AutoShrink properties to false.

But another problem: While exporting report to word or pdf,  X axis labels are displaying two times in the graph.

Please help me.

Regards,

B.Sridhar
0
Sridhar Bolisetti
Top achievements
Rank 1
answered on 30 Sep 2009, 02:13 PM
Hi,

Solved the X axis labels repeating in the export format putting xaxis.items.clear() before addrange()


Thanks.
Tags
General Discussions
Asked by
Sridhar Bolisetti
Top achievements
Rank 1
Answers by
Steve
Telerik team
Sridhar Bolisetti
Top achievements
Rank 1
Share this question
or