Andre Carneiro
Andre Carneiro

Reputation: 736

Telerik RadChart: add chart dynamically to Window object

First of all, I don´t know nothing about Visual Studio and C#(I´m using Visual Studio 2017).

I´m trying to follow the example from "Telerik" documentation website. It´s a WPF exeample( just for contextualize this ). But, the fact is I´m not able to plot a chart and I have no clue why. When I ran this code, just a blank windows appeared. There is no errors too, so I don´t know!

The code on MainWindow is this:

using System;
using System.Windows;
using System.Collections.Generic;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;

namespace Crap
{

    public partial class MainWindow {
        public MainWindow() {
            InitializeComponent();

            RadChart telerikChart = new RadChart();    

            //Configuring DefaultView
            telerikChart.DefaultView.ChartTitle.Content = "Year 2009";
            telerikChart.DefaultView.ChartTitle.HorizontalAlignment = HorizontalAlignment.Center;    //Chart Legend
            telerikChart.DefaultView.ChartLegend.UseAutoGeneratedItems = true;

            //Feeding Line Chart
            DataSeries lineSeries = new DataSeries();
            lineSeries.LegendLabel = "Turnover";
            lineSeries.Definition = new LineSeriesDefinition();
            lineSeries.Add(new DataPoint() { YValue = 154, XCategory = "Jan" });
            lineSeries.Add(new DataPoint() { YValue = 138, XCategory = "Feb" });
            lineSeries.Add(new DataPoint() { YValue = 143, XCategory = "Mar" });
            lineSeries.Add(new DataPoint() { YValue = 120, XCategory = "Apr" });
            lineSeries.Add(new DataPoint() { YValue = 135, XCategory = "May" });
            lineSeries.Add(new DataPoint() { YValue = 125, XCategory = "Jun" });
            lineSeries.Add(new DataPoint() { YValue = 179, XCategory = "Jul" });
            lineSeries.Add(new DataPoint() { YValue = 170, XCategory = "Aug" });
            lineSeries.Add(new DataPoint() { YValue = 198, XCategory = "Sep" });
            lineSeries.Add(new DataPoint() { YValue = 187, XCategory = "Oct" });
            lineSeries.Add(new DataPoint() { YValue = 193, XCategory = "Nov" });
            lineSeries.Add(new DataPoint() { YValue = 176, XCategory = "Dec" });
            telerikChart.DefaultView.ChartArea.DataSeries.Add(lineSeries);


        }
    }
}

I don´ want to use XAML for this. It is possible? This example make me believe yes. But if not, please tell me!

It seems something is missing to bind the MainWindow and chart. Or I´m doing this in absolutely wrong way. Can you help me, please?

Upvotes: 1

Views: 100

Answers (0)

Related Questions