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

Export into image with RadLegend

4 Answers 127 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Yonggu Kang
Top achievements
Rank 1
Iron
Yonggu Kang asked on 04 Mar 2014, 06:06 AM
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



   




4 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 06 Mar 2014, 11:35 AM
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!

0
Yonggu Kang
Top achievements
Rank 1
Iron
answered on 10 Mar 2014, 01:43 AM
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

0
Accepted
Yavor
Telerik team
answered on 10 Mar 2014, 12:42 PM
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.

0
Yonggu Kang
Top achievements
Rank 1
Iron
answered on 12 Mar 2014, 02:36 PM
Hi Yavor,

Thank you for your kind reply and sharing sample codes.

RGDS
Kang
Tags
ChartView
Asked by
Yonggu Kang
Top achievements
Rank 1
Iron
Answers by
Yavor
Telerik team
Yonggu Kang
Top achievements
Rank 1
Iron
Share this question
or