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

Add Legentes to a ChartView - CartesianChart

1 Answer 27 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
José Arthur
Top achievements
Rank 1
José Arthur asked on 13 Jun 2013, 09:05 PM
Here's my code

<telerikChart2:RadCartesianChart   x:Name="radChart" Margin="5,10,10,10">
    <telerikChart2:RadCartesianChart.Grid>
        <chartView:CartesianChartGrid MajorLinesVisibility="XY" MajorXLineDashArray="10" MajorXLinesRenderMode="All"/>
    </telerikChart2:RadCartesianChart.Grid>
    <telerikChart2:RadCartesianChart.VerticalAxis>
        <chartView:LinearAxis/>
    </telerikChart2:RadCartesianChart.VerticalAxis>
    <telerikChart2:RadCartesianChart.HorizontalAxis>
        <chartView:CategoricalAxis/>
    </telerikChart2:RadCartesianChart.HorizontalAxis>
</telerikChart2:RadCartesianChart

LineSeries obj = new LineSeries();
obj.Name = lstNomes[i];
obj.CategoryBinding = new PropertyNameDataPointBinding("AnoMes");
obj.ValueBinding = new PropertyNameDataPointBinding("Valor");
 
Color randomColor = new Color();
do
{
    if (rColor.ToString().Equals("#00000000") && randomColor.ToString() != "#00000000")
        rColor = randomColor;
    Random randonGen = new Random();
    randomColor = Color.FromArgb((byte)randonGen.Next(0, 254), (byte)randonGen.Next(255),
    (byte)randonGen.Next(254), (byte)randonGen.Next(255));
} while (randomColor == rColor);
 
rColor = randomColor;
string xaml = string.Format(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
    <Ellipse Fill=""{0}"" Height=""10"" Width=""10"" />
</DataTemplate>", randomColor.ToString());
obj.PointTemplate = System.Windows.Markup.XamlReader.Load(xaml) as DataTemplate;
obj.Stroke = new SolidColorBrush(randomColor);
radChart.Series.Add(obj);
radChart.Series[i].ItemsSource = lstChartAux;

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 18 Jun 2013, 12:30 PM
Hi José Arthur,

You can add a legend and bind its items to chart's LegendItems property as shown in this online example.


Best regards,
Ves
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ChartView
Asked by
José Arthur
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or