I need to translate the following xaml code into c# to build the real-time graph, but I always get reported that there are no series defined. If instead I directly use the xaml code in binding with my object it works regularly. Where am I doing wrong?
<TK:RadCartesianChart x:Name="RadCartesianChart"
Margin="0,18,0,0"
Palette="Windows8">
<TK:RadCartesianChart.HorizontalAxis>
<TK:CategoricalAxis LabelInterval="15"
ShowLabels="True" />
</TK:RadCartesianChart.HorizontalAxis>
<TK:RadCartesianChart.VerticalAxis>
<TK:LinearAxis LabelInterval="15"
ShowLabels="True" />
</TK:RadCartesianChart.VerticalAxis>
<TK:RadCartesianChart.SeriesProvider>
<TK:ChartSeriesProvider Source="{Binding Path=grafico[0].dataSERIE, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<TK:ChartSeriesProvider.SeriesDescriptors>
<TK:CategoricalSeriesDescriptor CategoryPath="etichetta"
ItemsSourcePath="dataITEM"
ValuePath="valore">
<TK:CategoricalSeriesDescriptor.Style>
<Style TargetType="TK:BarSeries">
<Setter Property="LegendSettings">
<Setter.Value>
<TK:SeriesLegendSettings Title="{Binding Path=serie, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
</Setter.Value>
</Setter>
</Style>
</TK:CategoricalSeriesDescriptor.Style>
</TK:CategoricalSeriesDescriptor>
</TK:ChartSeriesProvider.SeriesDescriptors>
</TK:ChartSeriesProvider>
</TK:RadCartesianChart.SeriesProvider>
</TK:RadCartesianChart>
C# code
RadCartesianChart ctrl = new RadCartesianChart() { Name = "RadCartesianChart" };
ctrl.Palette = ChartPalettes.Windows8;
ctrl.VerticalAxis = new LinearAxis() { ShowLabels = true, LabelInterval = 15 };
ctrl.HorizontalAxis = new CategoricalAxis() { ShowLabels = true, LabelInterval = 15 };
ChartSeriesProvider series = new ChartSeriesProvider()
{
Source = new Binding("grafico[0].dataSERIE") { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged },
};
CategoricalSeriesDescriptor seriesDescriptor = new CategoricalSeriesDescriptor
{
ItemsSourcePath = "dataITEM",
CategoryPath = "etichetta",
ValuePath = "valore",
Style = new Style(typeof(BarSeries))
};
seriesDescriptor.Style.Setters.Add(new Setter(BarSeries.LegendSettingsProperty,
new Binding("serie") { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }));
series.SeriesDescriptors.Add(seriesDescriptor);
ctrl.SeriesProvider = series;
Object data
public ObservableCollection<OGRecGrafico> grafico
{
get { return _grafico; }
set { _grafico = value; RaisePropertyChanged(() => grafico); }
}
private ObservableCollection<OGRecGrafico> _grafico = new ObservableCollection<OGRecGrafico>();
publicclassOGRecGrafico : NotificationObject
{
publicstring titolo { get; set; }
public ObservableCollection<OGRecGraficoSerie> dataSERIE { get; set; } = new ObservableCollection<OGRecGraficoSerie>();
}
publicclassOGRecGraficoSerie : NotificationObject
{
publicobject serie { get; set; }
public ObservableCollection<OGRecGraficoItem> dataITEM { get; set; } = new ObservableCollection<OGRecGraficoItem>();
}
publicclassOGRecGraficoItem : NotificationObject
{
publicobject serie
{
get { return _serie; }
set { _serie = value; RaisePropertyChanged(() => serie); }
}
privateobject _serie = null;
publicobject etichetta
{
get { return _etichetta; }
set { _etichetta = value; RaisePropertyChanged(() => etichetta); }
}
privateobject _etichetta = null;
publicobject valore
{
get { return _valore; }
set { _valore = value; RaisePropertyChanged(() => valore); }
}
privateobject _valore = null;
publicstring scriptSQL
{
get { return _scriptSQL; }
set { _scriptSQL = value; RaisePropertyChanged(() => scriptSQL); }
}
privatestring _scriptSQL = null;
}