Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2275
Series data all in same bar instead of each one
posted

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 );
 
				foreachUFChartDataSeries 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

Parents
No Data
Reply
  • 12875
    posted

    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.

Children