Combining of stacked bars and line? (Full Version)

All Forums >> [Dundas Chart] >> [Support] >> Dundas Chart for ASP.NET


per -> Combining of stacked bars and line? (1/22/2007 6:42:36 AM)


Is there a way that you could combine a stacked bars chart area and another chartarea with a line?

Jamie -> RE: Combining of stacked bars and line? (1/22/2007 5:11:07 PM)


Actually, I would recommend using the same ChartArea unless you specifically want to give the stacked column and the line each its own separate chart area.

Each Series has a Type property that you can set to your choice of chart type. At design-time:
  • Go to the Chart's Properties window
  • Select and open the Series collection
  • Select the series you want to customize
  • Set the Type property to a chart type
Or, you can use code like:

        Chart1.Series["MySeries1"].Type = SeriesChartType.StackedColumn;
       Chart1.Series["MySeries2"].Type = SeriesChartType.Line;

        Chart1.Series("MySeries1").Type = SeriesChartType.StackedColumn
       Chart1.Series("MySeries2").Type = SeriesChartType.Line

If you do want to use two separate chart areas, create a new chart area in the Chart's ChartAreas collection, then set the Series.ChartArea property on each series to the name of the appropriate chart area.

Hope this helps,

brettwgreen -> RE: Combining of stacked bars and line? (1/29/2007 9:26:15 AM)

The poster wanted to combine a StackedBar and a line chart.  Your example shows a StackedColumn.  When you try to combine a StackedBar and Line, it complains that they are not compatible.

Can I somehow 'rotate' the line chart to line up with my bars?  My dilemma is that I have up to 100 rows in my data to chart and if I try to display them as columns, I run out of room.  If I display them as rows, the chart will scale a bit better.

Brett Green

Jamie -> RE: Combining of stacked bars and line? (1/29/2007 12:01:16 PM)


It's a perfectly good point that the poster asked for "stacked bars" combined with a line, but typically clients don't share the terminology that Dundas Chart uses--when someone says they want a "bar" chart, they usually mean vertical bars, which is known as the Column chart type in Dundas Chart. I didn't mean to make that assumption though.

The Bar, StackedBar and Gantt chart types have their axes reversed, so that the X axis is on the left and the Y axis is on the bottom. This makes the Bar chart types and the Line chart type incompatible, because the "value" (Y) axes do not match up and it theoretically does not make sense to combine these two chart types. The X axis works very differently from the Y axis, and the Y axis of the bar chart cannot be the same as the X axis of the line chart.

If you do want to truly combine these two chart types, it is still possible in Dundas Chart. To start with, the two series with the different chart types need to be assigned to different chart areas:

Chart1.Series("StackedBar").ChartArea = "StackedBarChartArea";
Chart1.Series("Line").ChartArea = "LineChartArea";

The ChartAreas can then be positioned on top of each other by using manual positioning and by setting the BackColor property to transparent on the chart area on top:

Chart1.ChartAreas["StackedBarChartArea"].Position.Auto = false;
Chart1.ChartAreas["StackedBarChartArea"].Position.X = 5;
Chart1.ChartAreas["StackedBarChartArea"].Position.Y = 5;
Chart1.ChartAreas["StackedBarChartArea"].Position.Width = 90;
Chart1.ChartAreas["StackedBarChartArea"].Position.Height = 90;

Chart1.ChartAreas["LineChartArea"].Position.Auto = false;
 Chart1.ChartAreas["LineChartArea"].Position.X = 5;
 Chart1.ChartAreas["LineChartArea"].Position.Y = 5;
 Chart1.ChartAreas["LineChartArea"].Position.Width = 90;
 Chart1.ChartAreas["LineChartArea"].Position.Height = 90;
Chart1.ChartAreas["LineChartArea"].BackColor = Color.Transparent;

You may also need to manually set the chart areas' InnerPlotPosition in the same way. (This can all be done at design-time rather than in code, of course.) It would be up to you, though, how to handle which of the chart areas' axes should be visible and which should be hidden. As mentioned, the two series cannot share the same axis.

Chart1.ChartAreas["LineChartArea"].AxisX.Enabled = AxisEnabled.False;

Page: [1]