Hello guys, i have that lines in my code-behind:
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
this.InitializeComponent(); | |
MainWindowViewModel model = new MainWindowViewModel(); | |
RadChart1.DefaultView.ChartArea = model.MainChartArea; | |
RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true; | |
} | |
} | |
public class MainWindowViewModel | |
{ | |
private ChartArea _area; | |
public ChartArea MainChartArea | |
{ | |
get | |
{ | |
if (_area == null) | |
_area = CreateChartArea(); | |
return _area; | |
} | |
} | |
private ChartArea CreateChartArea() | |
{ | |
ChartArea area = new ChartArea(); | |
DataSeries ser1 = new DataSeries(); | |
ser1.Add(new DataPoint(23)); | |
ser1.Add(new DataPoint(45)); | |
ser1.Add(new DataPoint(33)); | |
ser1.Add(new DataPoint(12)); | |
ser1.Add(new DataPoint(50)); | |
ser1.LegendLabel = "Series 1 Label"; | |
area.DataSeries.Add(ser1); | |
DataSeries ser2 = new DataSeries(); | |
ser2.Add(new DataPoint(45)); | |
ser2.Add(new DataPoint(50)); | |
ser2.Add(new DataPoint(60)); | |
ser2.Add(new DataPoint(30)); | |
ser2.Add(new DataPoint(25)); | |
ser2.LegendLabel = "Series 2 Label"; | |
area.DataSeries.Add(ser2); | |
return area; | |
} | |
} |
and that is the XAML part:
<Grid x:Name="LayoutRoot"> | |
<control:RadChart x:Name="RadChart1"> | |
<control:RadChart.DefaultView> | |
<chart:ChartDefaultView> | |
<chart:ChartDefaultView.ChartLegend> | |
<chart:ChartLegend x:Name="CustomLegend" Header="Legend Header" UseAutoGeneratedItems="True"> | |
</chart:ChartLegend> | |
</chart:ChartDefaultView.ChartLegend> | |
<chart:ChartDefaultView.ChartTitle> | |
<chart:ChartTitle> | |
<TextBlock Text="Declarative RadChart"/> | |
</chart:ChartTitle> | |
</chart:ChartDefaultView.ChartTitle> | |
</chart:ChartDefaultView> | |
</control:RadChart.DefaultView> | |
</control:RadChart> | |
</Grid> |