Sorry, I've been away here is a sample of how I set up the chart.
This is my (sample) data set:
distribution = new DataSet();
distribution.Tables.Add(new DataTable());
distribution.Tables[0].Columns.Add("PersonName", typeof(System.String));
distribution.Tables[0].Columns.Add("A", typeof(System.Int32));
distribution.Tables[0].Columns.Add("B", typeof(System.Int32));
distribution.Tables[0].Columns.Add("C", typeof(System.Int32));
distribution.Tables[0].Rows.Add(new object[{"Liz", 1,2,5});
distribution.Tables[0].Rows.Add(new object[ { "Bob", 2, 1, 3 });
distribution.Tables[0].Rows.Add(new object[ { "Chris", 1, 0, 2 });
distribution.Tables[0].Rows.Add(new object[ { "Annie", 0, 1, 3 });
I ideally want a range set when the values are low so that the chart doesn't scale too much so if the highest total is 10 or less I do:
Without this the chart draws okay first time then messes up once a series is hidden
xASeries.RangeMax = 10;
xASeries.RangeMin = 0;
xASeries.RangeType = AxisRangeType.Custom;
Create a stack area layer and add it to the chart
ChartArea area = new ChartArea();
this.ultraChart2.CompositeChart.ChartAreas.Add(area);
ChartLayerAppearance stackArea = new ChartLayerAppearance();
stackArea.AxisX = xASeries;
stackArea.AxisY = yAxis;
stackArea.ChartArea = area;
stackArea.ChartType = ChartType.StackBarChart;
This causes the binding to be the right way round for us. Even without this the behaviour of the x-axis not updating to reflect the values in the bar can still be seen when hiding and showning series.
stackArea.SwapRowsAndColumns = true;
stackArea.Key = "StackBar";
I add the series via a loop nothing to special in here:
foreach (KeyValuePair<string, Color> severity in _severitySetup)
{
ISeries series = GetNumberSeries(severity.Key, severity.Value);
this.ultraChart2.Series.Add(series);
this.ultraChart2.CompositeChart.ChartLayers.FromKey("StackBar").Series.Add(series);
}
private NumericSeries GetNumberSeries(string columnName, Color columnColor)
{
Infragistics.UltraChart.Resources.Appearance.
NumericSeries seriesColumn = new NumericSeries();
seriesColumn.Data.DataSource = distribution.Tables[0];
seriesColumn.Data.LabelColumn = "PersonName";
seriesColumn.Data.ValueColumn = columnName;
seriesColumn.Key = columnName;
seriesColumn.Label = columnName;
PaintElement column = new PaintElement();
column.Fill = columnColor;
column.FillGradientStyle = GradientStyle.None;
column.FillOpacity = System.Convert.ToByte(102);
seriesColumn.PEs.Add(column);
return seriesColumn;
}
Then I hide the series on a check click event:
private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
{
UltraCheckEditor clickedEditor = sender as UltraCheckEditor; NumericSeries series = this.ultraChart2.CompositeChart.ChartLayers.FromKey("StackBar").Series.FromKey(clickedEditor.Text.ToString()) as NumericSeries; if(series != null)
{
series.Visible = clickedEditor.Checked;
}
}
[Infragistics] Max Rivlin:
The way a stacked bar chart works is each series represents one bar, comprised of sections that represent the points within the series. Having 2 series would mean the chart displays only 2 bars. Also, each series in a given layer must have the same number of points. I'm not really sure how you got the above images.
I looked into this as it set off warning bells, but the behaviour is the same with the stack setup normally. It may be by design, but if you hide a series without tearing down the chart then the X-axis values are ignored. It seems like the stack bar chart must always have one bar that stretches all the way across the chart (hence it ignoring axis range values) if this is the case and it's by design I would at least expect the x-axis to redraw as the y-axis and the legend do when you hide a series.