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
Hi Mike,
It looks like you are only creating only one “cycle” and your data is not being stacked.
Looking at your code but without your declaration for the UFChartDataPoint, it looks as if you are defining a SeriesName with a collection of datapoints. But each cycle is only adding one UFVolume value.
And you appear to have created the series as a Column series instead of a StackedColumnSeries.
If you have a sample that you can share, I might be able to give you more help with this.
If you look at the feature browser sample for Display – Series > Gallery – Category Series and change the type to a Stacked Column Series in the combobox, I believe you will see what you want to create.
The data is defined in a declaration of a collection of EnergyProduction items as follows:
public EnergyProductionDataSample()
{
this.Add(new EnergyProduction { Region = "America", Country = "Canada", Coal = 400, Oil = 100, Gas = 175, Nuclear = 225, Hydro = 350 });
this.Add(new EnergyProduction { Region = "Asia", Country = "China", Coal = 925, Oil = 200, Gas = 350, Nuclear = 400, Hydro = 625 });
this.Add(new EnergyProduction { Region = "Europe", Country = "Russia", Coal = 550, Oil = 200, Gas = 250, Nuclear = 475, Hydro = 425 });
this.Add(new EnergyProduction { Region = "Asia", Country = "Australia", Coal = 450, Oil = 100, Gas = 150, Nuclear = 175, Hydro = 350 });
this.Add(new EnergyProduction { Region = "America", Country = "United States", Coal = 800, Oil = 250, Gas = 475, Nuclear = 575, Hydro = 750 });
this.Add(new EnergyProduction { Region = "Europe", Country = "France", Coal = 375, Oil = 150, Gas = 350, Nuclear = 275, Hydro = 325 });
}
Obviously this is not what you need since it is hard coded but you can see that each item (Coal, Oil, Gas, etc.) has its own specific value and it is related to a Region and Country.
When you look at the charts, you’ll see that the category label is shown as the country with the associated items identified in the legend.
Let me know if this is what you had in mind and as I mentioned if you can provide a running sample I will be better able to give you a hand.
Marianne, thanks for your help, but maybe I was not clear. I do not want a stacked column report, just a column report.
As I was trying to communicate in my post, all of the cycles are appearing in the first cycle as per my posted graphic, and this is not what I want. What I hoped to convey was, I wanted each cycle to have its own data. So the blue line would be cycle 0, the black one to be in cycle 1, the grey one to be in cycle 2 and so forth.
Here is my class for the data point:
public class UFChartDataPoint { private const string m_ColumnLabel = "Volume"; public string ColumnLabel { get { return m_ColumnLabel; } } public double DataPointValue { get; set; } }
I can't provide you with any more of a running sample as per your request, as you have all of my code I am using to create the chart (except for the data point which is provided above). Can you go from here?
Thank you,
Anything???
Anybody?
Marianne, thank you for your help on this issue. I can see from your example code where I went wrong. Thanks again.
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.