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

pie chart legend is showing item1,2...

4 Answers 428 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
sabarishbabu
Top achievements
Rank 1
sabarishbabu asked on 31 Oct 2009, 07:20 AM
Hi all,

  I am using telerik reporting tool.i am passing from date and todate from aspx page and displaying chart on the report viewer.

Chart is coming correctly but legend is showing as item1, item2,item3..I want to show the name in legends and show the  time in percentage in Y columns(ex:   series.DefaultLabelValue = "#%").I have the datacolumn as "name" and "usage_time".

"usage_time"  should be display as percentage and "name" should in the legend

please tell me how to do it?

i am putting my coding for your reference

in aspx page:



                DateTime dtFromDate = (DateTime)dpFromDate.SelectedDate;
                DateTime dtToDate = (DateTime)dpToDate.SelectedDate;


                ReportProperty oPro = new ReportProperty();
                oPro.FromDate = dtFromDate;
                oPro.ToDate = dtToDate;

                telerikReportGraph oReport = new telerikReportGraph();              
                oReport.GenerateReport(oPro);
                reportviewer.Report = oReport;


in reporting.cs

public void GenerateReport(ReportProperty pro)
        {

            DateTime fromDate = pro.FromDate;
            DateTime toDate = pro.ToDate;
           
            titleTextBox.Value = "User/Time Pie Chart";
            
            
            ds = DBMethods.GetDetailsForUserChart(1, fromDate, toDate);
            


            ChartSeries series = new ChartSeries();           
            series.DataYColumn = "usage_time";
            series.Type = ChartSeriesType.Pie;           
          
            series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            series.Appearance.LabelAppearance.Visible = true;
            series.Appearance.ShowLabelConnectors = true;
            series.Appearance.ShowLabels = true;
            series.Appearance.DiameterScale = 0.6;
        
            chart1.ChartTitle.TextBlock.Visible = false;
            chart1.ChartTitle.Visible = true;
            chart1.Legend.Visible = true;
            series.DefaultLabelValue = "#%";
            chart1.Series.Add(series);



  foreach (DataRow row in ds.Tables[0].Rows)
            {
                


                ChartSeriesItem item = new ChartSeriesItem();
              
                item.Name = (string)row["name"];
                item.Appearance.Exploded = true;
                series.DefaultLabelValue = "#%";

            }


 this.chart1.NeedDataSource += new System.EventHandler(this.chart1_NeedDataSource_1);
}
 private void chart1_NeedDataSource_1(object sender, EventArgs e)
        {
    (sender as Telerik.Reporting.Processing.Chart).DataSource = ds;

}

4 Answers, 1 is accepted

Sort by
0
sabarishbabu
Top achievements
Rank 1
answered on 02 Nov 2009, 05:49 AM
can you anybody tell me the solution?it is urgent for my project.


Thanks for your help
0
Steve
Telerik team
answered on 02 Nov 2009, 01:38 PM
Hello sabarishbabu,

Setting the LegendDisplayMode property to ItemLabels for the series is correct
and using the Name property of the series items to contain the value of the data field which you want to show in the legend as well. If you want to have the name in the item labels as well, you should set the item.Label.TextBlock.Text property as well.
The problem here is that you do this manually as you should, but after that you bind the chart in the NeedDataSource event, which means that you wipe out all these settings. When you bind the chart through the DataSource property, it would automatically create the series and items and this is not what we want.
In other words you need to populate the series programmatically and not bind the chart e.g.:

private void chart1_NeedDataSource(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Value", typeof(double));
            table.Rows.Add(new object[] { "Product A", 10 });
            table.Rows.Add(new object[] { "Product B", 20 });
            table.Rows.Add(new object[] { "Product C", 30 });
            Processing.Chart chart = (Processing.Chart)sender;
            Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition;
            ChartSeries s = chartDef.Series[0];
            s.Clear();
            s.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
            foreach (DataRow row in table.Rows)
            {
                ChartSeriesItem item = new ChartSeriesItem();
                item.YValue = (double)row["Value"];
                item.Name = (string)row["Name"];                 
                item.Label.TextBlock.Text = (string)row["Name"] + " - #%";
                s.Items.Add(item);
            }
             
        }


Kind 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
sabarishbabu
Top achievements
Rank 1
answered on 04 Nov 2009, 05:02 AM
Thank you. it is working

i changed the line "ChartSeriesItem item =chartdef.series[]" to  ChartSeriesItem item = new ChartSeriesItem();because i am getting error in "chartdef.series[]".





0
Antonio Simoes
Top achievements
Rank 1
answered on 19 May 2010, 12:17 PM

I followed your example and if I don't set the datasource property of chartDef I get a "No or Empty Series" graph...am I missing anything?

here's my NeedDataSource event code:

            

 

private void chart1_NeedDataSource(object sender, EventArgs e)

 

{
            List<CategoryReport> categorias = new List<CategoryReport>();  
            List<Issue> issues = Issue.GetIssuesByProjectId(1);  
            var group = issues.GroupBy(x => x.CategoryName).ToList();  
 
            Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;  
            Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;  
            ChartSeries series = new ChartSeries();  
            defChart.Series.Add(series);  
            series.Clear();  
            series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;  
 
            foreach (var item in group)  
            {  
                ChartSeriesItem serieItem = new ChartSeriesItem();  
                serieItem.YValue = (double)item.Count();  
                serieItem.Name = item.Key;  
                serieItem.Label.TextBlock.Text = item.Key + " - #%";  
                serieItem.Appearance.Exploded = true;  
                series.Items.Add(serieItem);  
 

 

                //categorias.Add(new CategoryReport() { CategoryName = item.Key, IssueCount = item.Count() });

 

            }

                //procChart.DataSource = categorias;

 

}


If I set the datasource property to be my categorias List my graph is generated properly with the exception my labels showing Item 1,2,3,4, etc...
Tags
General Discussions
Asked by
sabarishbabu
Top achievements
Rank 1
Answers by
sabarishbabu
Top achievements
Rank 1
Steve
Telerik team
Antonio Simoes
Top achievements
Rank 1
Share this question
or