I'm doing a column chart and all of me series data is in the same series instead of each one.
I'm doing this dynamically. Here is my code behind:
private void FillUFChartSeries( Treatment CurrentTreatment ) { try { ColumnSeries series; UFStackSeries UFStackSeriesSet = new UFStackSeries( CurrentTreatment ); NumericYAxis yAxis = new NumericYAxis(); CategoryXAxis xAxis = new CategoryXAxis(); xAxis.ItemsSource = UFStackSeriesSet; xAxis.Label = "{SeriesName}"; this.UFChart.Axes.Add( xAxis ); this.UFChart.Axes.Add( yAxis ); foreach( UFChartDataSeries CurrentUFChartDataItem in UFStackSeriesSet ) { series = new ColumnSeries(); series.ItemsSource = CurrentUFChartDataItem.DataPoints; series.ValueMemberPath = "DataPointValue"; series.Title = CurrentUFChartDataItem.SeriesName; series.XAxis = xAxis; series.YAxis = yAxis; this.UFChart.Series.Add( series ); } } catch ( Exception ) { throw; } }
Here is the code for how I am structuring the data:
public class UFStackSeries : ObservableCollection<UFChartDataSeries> { public UFStackSeries( Treatment CurrentTreatment ) { string SeriesName; ObservableCollection<UFChartDataPoint> DataPoints = new ObservableCollection<UFChartDataPoint>(); foreach ( Cycle c in CurrentTreatment.Cycles ) { SeriesName = "Cycle " + c.CycleIndex.ToString(); DataPoints = new ObservableCollection<UFChartDataPoint>(); DataPoints.Add( new UFChartDataPoint() { DataPointValue = c.UFVolume } ); this.Add( new UFChartDataSeries() { SeriesName = SeriesName, DataPoints = DataPoints } ); } } } /// /// Data series for the UFChart /// public class UFChartDataSeries { public string SeriesName { get; set; } public ObservableCollection<UFChartDataPoint> DataPoints { get; set; } }
What I want is for each cycle to have it's own data, but all the data is being put into cycle 0, and there are spots for all of the cycles, but they don't have any data put in them.
Here is what the graph actually looks like:
Thanks,
Mike
Marianne, thank you for your help on this issue. I can see from your example code where I went wrong. Thanks again.
Hi Mike,
Thanks for letting know. I'll wait to hear from you when you return.
I'm out of town and on. Vacation until Aug 1, will review when I get back in town.
I don't know if you have had a chance to review my sample or if you have any questions.
Please let me know if there is anything more i can help you with.
I’m attaching my sample. You’ll see that I modified your code to create a series of datapoints in a single series. Each datapoint has a columnname that is used as the label. I also added a legend to your chart to make it easier for you to see that “Series” was added with multiple labeled datapoints.
If you need to create multiple series then you would need to add to the UFStackSeriesSet.
Please let me know if you have any questions.