Export into image with RadLegend

5 posts, 1 answers
  1. YongKoo Kang
    YongKoo Kang avatar
    101 posts
    Member since:
    Jan 2010

    Posted 04 Mar 2014 Link to this post

    Hi,telerik

    I have to create chart by code and export into image with legend.
    After reading your doc and related threads,unfortunately can't find
    right answer how to create legend with code. My question is

    1. Add legend into RadCartesianChart by code
        Following is my code.

      
    RadCartesianChart cartChart = new RadCartesianChart();
              cartChart.HorizontalAxis = new LinearAxis() { Maximum = 50, Minimum = 17, MajorStep = 3 };
              cartChart.VerticalAxis = new LinearAxis() { LabelFormat = "p0" };
     
              var resultList = CordXy.GetMonthFecundity();
     
              ScatterLineSeries pregSeries = new ScatterLineSeries() { Stroke = new SolidColorBrush(Colors.Blue), StrokeThickness = 2 }; ;
              pregSeries.XValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Age" };
              pregSeries.YValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Num" };
     
              // ADD Legend
              pregSeries.LegendSettings = new SeriesLegendSettings() { Title = "TEST" };
               
              pregSeries.ItemsSource = resultList[0] as IEnumerable<CordXy>;
              cartChart.Series.Add(pregSeries);
     
              ScatterLineSeries delSeries = new ScatterLineSeries() { Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 2 }; ;
              delSeries.XValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Age" };
              delSeries.YValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Num" };
     
               // ADD Legend
              delSeries.LegendSettings = new SeriesLegendSettings() { Title = "TEST2" };
     
              delSeries.ItemsSource = resultList[1] as IEnumerable<CordXy>;
              cartChart.Series.Add(delSeries);
     
               // STUCK HERE...
              //cartChart.LegendItems.Add(pregSeries.LegendSettings);
              //cartChart.LegendItems.Add(delSeries.LegendSettings);

    2. Export chart into image with legend
        All sample shows legend is placed outside of chart control.
        Is it possible to export chart with legend ? or Should I go back to outdated RadCharting ?

    TIA.

    RGDS
    Kang



       




  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 06 Mar 2014 Link to this post

    Hi,

    The RadLegend is a separate control, which shows legend items. The chart has build-in support for RadLegend and it provides legend items through the LegendItems collection. Here is what you need to do:

    // STUCK HERE...
    RadLegend legend = new RadLegend();
    legend.Items = cartChart.LegendItems;

    Of course you need to add it to the visual tree in order to display it, but these 2 rows of code are sufficient for the legend configuration.

    Regards,
    Yavor
    Telerik

    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

  3. UI for WPF is Visual Studio 2017 Ready
  4. YongKoo Kang
    YongKoo Kang avatar
    101 posts
    Member since:
    Jan 2010

    Posted 09 Mar 2014 in reply to Yavor Link to this post

    Hi Yavor,

    Thanks for your kind reply for my basic question.

    To display legend items,you said that insert lengend into visual tree,
    but seeing your sample, legend is always located outside of chart control.

    What I want is to export chart into image with legend items altogether.
    Could you advice me again ?

    RGDS
    Kang

  5. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 10 Mar 2014 Link to this post

    Hi,

    Indeed the legend is always outside the Chart, because it is a separate control. You can export the chart and the legend by exporting the panel that holds them. Here is some code:

    this.chartGrid = new Grid();
    this.chartGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
    this.chartGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
    this.chartGrid.Children.Add(cartChart);
    this.chartGrid.Children.Add(legend);
    this.LayoutRoot.Children.Add(this.chartGrid);

    Check the attached project.

    Regards,
    Yavor
    Telerik

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

  6. YongKoo Kang
    YongKoo Kang avatar
    101 posts
    Member since:
    Jan 2010

    Posted 12 Mar 2014 in reply to Yavor Link to this post

    Hi Yavor,

    Thank you for your kind reply and sharing sample codes.

    RGDS
    Kang
Back to Top
UI for WPF is Visual Studio 2017 Ready