Showing legend name in Chart ItemLabels

5 posts, 0 answers
  1. Manish Kumar
    Manish  Kumar avatar
    62 posts
    Member since:
    Feb 2010

    Posted 18 Nov 2010 Link to this post

    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
  2. Evgeni "Zammy" Petrov
    Admin
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 22 Nov 2010 Link to this post

    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
  3. Manish Kumar
    Manish  Kumar avatar
    62 posts
    Member since:
    Feb 2010

    Posted 24 Nov 2010 Link to this post

    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
  4. Manish Kumar
    Manish  Kumar avatar
    62 posts
    Member since:
    Feb 2010

    Posted 24 Nov 2010 Link to this post

    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
  5. Evgeni "Zammy" Petrov
    Admin
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 29 Nov 2010 Link to this post

    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
Back to Top