Hi,
I'm having an issue displaying series on a chart without having things hardcoded in the xaml( I can easily display a series with hardcoded things in the xaml and setting the charts datacontext to my ObservableCollection). But as soon as try to create my own series in the code behind, and try to throw it onto the chart, nothing gets displayed.
Here is my code for creating a series/putting it on the chart.
C#:
var listOfPoints1 = new ObservableCollection<DataPoint>()
{ new DataPoint() {Subject ="subject_1", X = 0, Y = 25.68}, new DataPoint() {Subject ="subject_1",X = 35, Y = 5.68}, new DataPoint() {Subject ="subject_1",X = 58, Y = 45.56}, new DataPoint() {Subject ="subject_1",X = 65, Y = 70.68}, new DataPoint() {Subject ="subject_1",X = 165, Y = 125.68}, new DataPoint() {Subject ="subject_1",X = 265, Y = 555.68}, new DataPoint() {Subject ="subject_1",X = 400, Y = 325.68}, }; NumericXAxis x = new NumericXAxis(); NumericYAxis y = new NumericYAxis();
ScatterSplineSeries series = new ScatterSplineSeries(); series.XAxis = x; series.YAxis = y; series.XMemberPath = "X"; series.YMemberPath = "Y"; series.ItemsSource = listOfPoints1; series.Title = "Subject 1"; series.Thickness = 3; series.MarkerType = MarkerType.None; xamChart1.Series.Add(series);
and my XAML looks like this:
<ig:XamDataChart Name="xamChart1" HorizontalZoomable="True" HorizontalZoombarVisibility="Collapsed" Padding="10" VerticalZoomable="True" VerticalZoombarVisibility="Collapsed" > <ig:XamDataChart.Axes> <ig:NumericXAxis x:Name="ScatterSplineXAxis" /> <ig:NumericYAxis x:Name="ScatterSplineYAxis" /> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> </ig:XamDataChart.Series> </ig:XamDataChart>
Any help would be appreciated.
Thanks,
Nicolas
You also need to add your axes to the chart.
-Graham
There are axes to the chart, unless I'm completely missing something which I feel I've tried everything. I can show data on the graph if I bind something to the datasource of the actual chart and have a hardcoded series on the chart i.e:
<ig:ScatterSplineSeries ItemsSource="{Binding}" Thickness="3" XMemberPath="X" YMemberPath="Y" MarkerType="None" XAxis="{Binding ElementName=ScatterSplineXAxis}" YAxis="{Binding ElementName=ScatterSplineYAxis}" > </ig:ScatterSplineSeries>
But that's not what I'm looking for, I need to be able to dynamically add multiple series in the code behind and have them display on the chart.
Nicolas,
But those axes are not the ones you are actually associating with the series. You either need to pull the ones out of the chart and assign those to the series or comment the axes out of the Xaml and then add them to the chart in your code behind:
xamChart1.Axes.Add(x);
xamChart1.Axes.Add(y);
Recently i need to create pdf417 barcode uing c#.I want to dispay barcodes on a chart in c#. I'm using the Chart control from .net 4.0 in my C# WinForms app. I have two series' of data displayed as line graphs. I'm graphing basically a supply and demand as a function of time. I want the demand to be a solid line of some colour, and the supply to be a dashed line of the same colour. I can set the colour fine, but I can't find anywhere where I can set the line style to be dashed.Any advice?