Question

Stacked Bar Chart where X axis labels/range is different between series

Posted 3 years ago by Avatar Bill Leibold

Hey,

Is it possible to create a stacked Bar chart with multiple series that may contain different groups of X axis labels or values?

Is there a way to establish the X axis range or string values that are common to all configured series data before adding the series data?

Currently, it appears that the first configured/added series establishes the X axis range of values.

I would prefer to use a stacked Bar chart vs. multiple Bar charts to visualize what is mostly common data.

 

Best regards,

Bill


Comments (6)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Bill,

You should be able to do this if you explicitly define the axis in your XAML.  Then you have control over the major/minor ticks and how far apart they are.  For instance, this XAML seemed to work when I tried it on a couple series that had Tuple<int,int> data:

<charts:XYChart>
	<charts:XYChart.XAxes>
		<charts:XYDoubleAxis TickMajorInterval="5" TickMinorInterval="1" />
	</charts:XYChart.XAxes>
	<charts:XYChart.YAxes>
		<charts:XYDoubleAxis Minimum="0" Maximum="6" TickMajorInterval="2" TickMinorInterval="1" />
	</charts:XYChart.YAxes>
	<charts:BarSeries StackKind="Normal" ItemsSource="{Binding ElementName=window, Path=Data1}" XPath="Item1" YPath="Item2" />
	<charts:BarSeries StackKind="Normal" ItemsSource="{Binding ElementName=window, Path=Data2}" XPath="Item1" YPath="Item2" />
</charts:XYChart>

Actipro Software Support
Posted 3 years ago by Bill Leibold

Hey,

I don't think this will work for a grouped type axis, which is what I am using.  My X axis consists of string labels that are defined using a label function.  The Bar Series elements are created programmatically.

 <charts:XYChart.YAxes>
    <charts:XYDoubleAxis x:Name="YAxisNormal" LabelFormat="{}{1:0}" Style="{StaticResource AxisStyle}" Baseline="0" Minimum="0"/>
 </charts:XYChart.YAxes>

 <charts:XYChart.XAxes>
   <charts:XYGroupedAxis x:Name="XAxisGrouped" AreLabelsVisible="True" LabelAngle="-75"
                                LabelStyle="{StaticResource XAxisLabelStyle}" Style="{StaticResource XAxisStyle}"/>
 </charts:XYChart.XAxes>
Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Bill,

Have you checked into the XYGroupedAxis.GroupingFunc?  You can specify a function there that takes two data items and returns a boolean whether they are grouped.


Actipro Software Support
Posted 3 years ago by Bill Leibold

Hey,

I tried using the GroupedFunc property, but this does not resolve the issue. It appears that the first series data that is added establishes the full range of the X axis string labels using the LabelFunc property. If another series is added to the chart with an additional few X axis labels that are not present in the first added series data, then the missing or new data item labels are just automatically stacked onto the first bar in the chart as they don't have an existing X axis label or range item to plot against.

Is there a way to establish programmatically the range of data to use for the X axis (using GroupedAxis because of string label identifiers), prior to adding the series data or does it always require automatic calculation when the first series data is added?

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

I believe it's set from the data and can't be modified programmatically.  Could you possibly update the first series to be a union of all the group possibilities?  And for data points not in the first series that are in the second series, put a zero value in the first series for them.  That would likely establish all the groups you'd need then.


Actipro Software Support
Posted 3 years ago by Bill Leibold

Hey,   I used your suggestion on establishing a common set of series data and this works fine!

Thanks for the help.

Information The latest build of this product (2018.1 build 0672) was released 2 months ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.