Add Legentes to a ChartView - CartesianChart

2 posts, 0 answers
  1. José Arthur
    José Arthur avatar
    2 posts
    Member since:
    Jun 2010

    Posted 13 Jun 2013 Link to this post

    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;
  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 18 Jun 2013 Link to this post

    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.

  3. DevCraft banner
Back to Top