Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Stacked Bar Chart Issue

Last post 07-09-2008 3:48 by spiketherat. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-27-2008 7:22

    Stacked Bar Chart Issue

    I'm certain I'm missing something obivous here but we have a stacked barchat that is part of a composite chart. I set it up fairly simpley binding to a datatable with data in the format:

    Person  A  B  C D
    Liz         1  3  0 4

    etc..

    And then set up the series:

    NumericSeries seriesColumn = new NumericSeries();
    seriesColumn.Data.DataSource = distribution.Tables[0];
    seriesColumn.Data.LabelColumn =
    "PersonName";
    seriesColumn.Data.ValueColumn = "A";

    Once it's bound series can be switched on and off using checkboxes, and I just hide the series on the chart by setting the visiblity property but when this is done the bars move and the values nolonger match the x -axis labels. In fact I've also noticed that setting  the RangeMax Min values also cause the bars to be drawn wrongly.

    What am I missing?

     

    • Post Points: 20
  • 07-02-2008 14:09 In reply to

    Re: Stacked Bar Chart Issue

    Strange behavior, but I was unable to reproduce it. Can you post a more complete sample of how the chart is set up along with sample data? I'm a bit confused by the posted images. 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.

    • Post Points: 20
  • 07-07-2008 5:39 In reply to

    Re: Stacked Bar Chart Issue

    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.

    • Post Points: 20
  • 07-08-2008 14:01 In reply to

    Re: Stacked Bar Chart Issue

    Answer

    I tried reusing your code as much as I could, but still everything seems to work fine. Maybe you need to apply the latest hotfix. By the way, what version (and build) of the chart are you using? I used 2008 vol 2 build 1000.

    Here's what I used:

    DataSet distribution;

    private void Form1_Load(object sender, EventArgs e)
    {
    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 });

    ChartArea
    area = new ChartArea();
    ultraChart1.CompositeChart.ChartAreas.Add(area);

    AxisItem x = new AxisItem(ultraChart1, AxisNumber.X_Axis);
    x.DataType =
    AxisDataType.Numeric;
    x.RangeMax = 10;
    x.RangeMin = 0;
    x.RangeType =
    AxisRangeType.Custom;
    x.Labels.ItemFormat =
    AxisItemLabelFormat.DataValue;
    area.Axes.Add(x);

    AxisItem y = new AxisItem(ultraChart1, AxisNumber.Y_Axis);
    y.DataType =
    AxisDataType.String;
    area.Axes.Add(y);

    ChartLayerAppearance stackLayer = new ChartLayerAppearance();
    stackLayer.AxisX = x;
    stackLayer.AxisY = y;
    stackLayer.ChartArea = area;
    stackLayer.ChartType =
    ChartType.StackBarChart;
    stackLayer.SwapRowsAndColumns =
    true;
    stackLayer.Key =
    "StackBar";
    ultraChart1.CompositeChart.ChartLayers.Add(stackLayer);

    ISeries[ series = new ISeries[5];
    series[0] = GetNumberSeries(
    "A", Color.Red);
    series[1] = GetNumberSeries(
    "B", Color.Blue);
    series[2] = GetNumberSeries(
    "C", Color.Green);
    series[3] = GetNumberSeries(
    "A", Color.Brown);
    series[4] = GetNumberSeries(
    "B", Color.Yellow);

    stackLayer.Series.AddRange(series);
    ultraChart1.CompositeChart.Series.AddRange(series);
    }

    private NumericSeries GetNumberSeries(string columnName, Color columnColor)
    {
    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;
    }

    For my checkboxes, I did something like this:
    ((NumericSeries)ultraChart1.CompositeChart.Series[index]).Visible = checkbox.Checked;

    • Post Points: 20
  • 07-08-2008 14:15 In reply to

    Re: Stacked Bar Chart Issue

    Hmm strange, it must be a version thing then. I know we are using 8.1 though I'm not sure what build I'll check when I get back in to tomorrow. I'll also upgrade and use the code as you have an let you know how it works out. Fingers crossed because this has been driving me nuts.

     EDIT:

    Well I couldn't wait till tomorrow so I've just downloaded the trial version of 8 vol 2 and set up the code above and it's working just as you said. I'll let you know what version we are running tomorrow but based on what I've just seen it must be that. Thank you, and sorry I feel like a bit of a plank now.

    • Post Points: 5
  • 07-09-2008 3:48 In reply to

    Re: Stacked Bar Chart Issue

    Just for further information we were using version 8.1.20081.1000 of the chart.

    We've upgraded the app to the the vol2 release and the issue has been fixed.
    Thanks again for your help Max.

    • Post Points: 5
Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems