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">
            <chartView:CartesianChartGrid MajorLinesVisibility="XY" MajorXLineDashArray="10" MajorXLinesRenderMode="All"/>
    LineSeries obj = new LineSeries();
    obj.Name = lstNomes[i];
    obj.CategoryBinding = new PropertyNameDataPointBinding("AnoMes");
    obj.ValueBinding = new PropertyNameDataPointBinding("Valor");
    Color randomColor = new Color();
        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="""">
        <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[i].ItemsSource = lstChartAux;
  2. Ves
    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,

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top