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

Showing legend name in Chart ItemLabels

4 Answers 63 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Manish Kumar
Top achievements
Rank 1
Manish Kumar asked on 18 Nov 2010, 12:02 PM
Hi

Is there any way where in we can display for the last occuring chartarea datapoint itemlabel as the chart legend name of the LineChart.

thanks
Manish Kumar

4 Answers, 1 is accepted

Sort by
0
Evgeni "Zammy" Petrov
Telerik team
answered on 22 Nov 2010, 05:58 PM
Hi Manish Kumar,

Can you please provide more details about your scenario. A screenshot with the expected result would be helpful. Thank you.

Sincerely,
Evgeni "Zammy" Petrov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Manish Kumar
Top achievements
Rank 1
answered on 24 Nov 2010, 02:26 PM
Hi

I have attached a dummy screen to give an idea of how the chart should look like afer giving the legend name at the end of the series.


thanks
Manish Kumar
0
Manish Kumar
Top achievements
Rank 1
answered on 24 Nov 2010, 02:29 PM
Hi

I have attached a dummy screen to give an idea of how the chart should look like afer giving the legend name at the end of the series.


thanks
Manish Kumar
0
Evgeni "Zammy" Petrov
Telerik team
answered on 29 Nov 2010, 07:34 AM
Hi Manish Kumar,

This is not supported out-of-the-box by the chart but there is a easy solution to this. You need to subscribe to DataBound and manually put the Label information for the last DataPoint in LegendItem.

Here is  code snippet:

    ...
   RC1.DataBound += new EventHandler<ChartDataBoundEventArgs>(RC1_DataBound);
}
 
void RC1_DataBound(object sender, ChartDataBoundEventArgs e)
{
    DataSeriesCollection dataSeriesCollection = RC1.DefaultView.ChartArea.DataSeries;
    for (int i = 0; i < dataSeriesCollection.Count; i++)
    {
        DataSeries dataSeries = dataSeriesCollection[i];
        DataPoint lastDataPointInSeries = dataSeries.Last<DataPoint>();
        var legendItem = (RC1.DefaultView.ChartLegend as ItemsControl).Items[i] as ChartLegendItem;
        legendItem.Label = lastDataPointInSeries.Label;
    }
}

 Hope this is going to help you out.

Best wishes,
Evgeni "Zammy" Petrov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Chart
Asked by
Manish Kumar
Top achievements
Rank 1
Answers by
Evgeni "Zammy" Petrov
Telerik team
Manish Kumar
Top achievements
Rank 1
Share this question
or