I have a composite chart with a barchart and a stacked bar chart. I need the stacked bar chart to display behind the bar chart because it shows a rating for the bar chart with a different colour for each section. I have everything working ok except that when I add the stacked bar chart first, I don't get any labels on my Y axis. The label values are supposed to be defined by the bar chart. If I add the bar chart first, I get the labels, but the bars appear behind the colours of the stacked bar chart and it is hard to read.
For this screenshot, I added the bar chart, then the stacked bar chart, the the bar chart a second time. I'm sure there is a better way to do this. Any help would be appreciated.
Here is my code if you want to see it:
myChart.ChartType = ChartType.Composite
Dim area As ChartArea = New ChartArea()
myChart.CompositeChart.ChartAreas.Add(area)
Dim YAxis As AxisItem = New AxisItem(myChart, AxisNumber.Y_Axis)
YAxis.DataType = AxisDataType.String
YAxis.SetLabelAxisType = Infragistics.UltraChart.Core.Layers.SetLabelAxisType.GroupBySeries
YAxis.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel
YAxis.Labels.SeriesLabels.Format = AxisSeriesLabelFormat.SeriesLabel
area.Axes.Add(YAxis)
Dim XAxis As AxisItem = New AxisItem(myChart, AxisNumber.X_Axis)
XAxis.DataType = AxisDataType.Numeric
XAxis.Labels.ItemFormat = AxisItemLabelFormat.DataValue
area.Axes.Add(XAxis)
With XAxis
.SetLabelAxisType = Infragistics.UltraChart.Core.Layers.SetLabelAxisType.ContinuousData
.TickmarkInterval = 0
.Visible = True
.LineThickness = 1
.TickmarkStyle = Infragistics.UltraChart.Shared.Styles.AxisTickStyle.Smart
.Extent = 35
Try
.RangeType = Infragistics.UltraChart.Shared.Styles.AxisRangeType.Custom
.RangeMin = 0
.RangeMax = 120
Catch ex As Exception
End Try
With .Labels
.ItemFormatString = "<DATA_VALUE:0>"
.HorizontalAlign = Drawing.StringAlignment.Near
.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.VerticalLeftFacing
.VerticalAlign = Drawing.StringAlignment.Center
.FontColor = Drawing.Color.Gray
With .Layout
.Behavior = Infragistics.UltraChart.Shared.Styles.AxisLabelLayoutBehaviors.Auto
End With
With .SeriesLabels
With YAxis
.Extent = 70
.ItemFormatString = "<ITEM_LABEL>"
.HorizontalAlign = Drawing.StringAlignment.Far
.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.Horizontal
.Behavior = Infragistics.UltraChart.Shared.Styles.AxisLabelLayoutBehaviors.None
With myChart
.Height = 500
.Width = 900
With .ColorModel
.AlphaLevel = 255
.ModelStyle = Infragistics.UltraChart.Shared.Styles.ColorModels.LinearRange
.ColorBegin = Drawing.Color.Gray
.ColorEnd = Drawing.Color.Gray
With .Data
.SwapRowsAndColumns = True
.ZeroAligned = True
With .EmptyStyle
.LineStyle.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Dash
myChart.CompositeChart.Series.Add(MainSeries)
myChart.CompositeChart.Series.Add(RatingSeries)
Dim MainChartLayer As ChartLayerAppearance = New ChartLayerAppearance()
MainChartLayer.AxisX = XAxis
MainChartLayer.AxisY = YAxis
MainChartLayer.ChartArea = area
MainChartLayer.ChartType = ChartType.BarChart
MainChartLayer.Series.Add(MainSeries)
MainChartLayer.SwapRowsAndColumns = True
Dim MainChartAppearance As New BarChartAppearance
Dim MainChartText As New ChartTextAppearance
MainChartText.ItemFormatString = "<DATA_VALUE:0>"
MainChartText.Visible = True
MainChartText.HorizontalAlign = StringAlignment.Far
MainChartAppearance.ChartText.Add(MainChartText)
MainChartText.Column = -2
MainChartText.Row = -2
MainChartLayer.ChartTypeAppearance = MainChartAppearance
Dim RatingLayer As ChartLayerAppearance = New ChartLayerAppearance()
RatingLayer.AxisX = XAxis
RatingLayer.AxisY = YAxis
RatingLayer.ChartArea = area
RatingLayer.ChartType = ChartType.StackBarChart
RatingLayer.Series.Add(RatingSeries)
myChart.CompositeChart.ChartLayers.Add(MainChartLayer)
myChart.CompositeChart.ChartLayers.Add(RatingLayer)
You should display the two layers on different Y axes. Your stack bar chart has one series and therefore displays one (stacked) bar, so the Y axis that's used to display that bar will always display at most one item from each layer. If you add another Y axis this won't happen. Here's the code snippet that should help you:
Dim YAxisRating As AxisItem = New AxisItem(myChart, AxisNumber.Y_Axis)YAxisRating.DataType = AxisDataType.StringYAxisRating.SetLabelAxisType = Infragistics.UltraChart.Core.Layers.SetLabelAxisType.GroupBySeriesYAxisRating.Labels.ItemFormat = AxisItemLabelFormat.ItemLabelYAxisRating.Labels.SeriesLabels.Format = AxisSeriesLabelFormat.SeriesLabelarea.Axes.Add(YAxisRating)
RatingLayer.AxisX = XAxisRatingLayer.AxisY = YAxisRating
Perfect, Thank you. I had tried making a second Y axis before I posted but I must have been doing something wrong...
thanks!