Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
630
Composite Column and Line - Legend config??
posted

Here is a sample of a problem I am having with a column / line composite chart.  

I can't seem to get the legend to show what I want.  It should show one item for the columns (Dollars), and a white item for the line (Price)  to show the user what they are looking at. 

First, it's showing all the values for the Columns, and none of the values for the line, even though I sent it both chart layers??  But that's not even what I want, I just want two items, one for Dollars (blue) and one for Price (white) 

Just not getting how the Legend can be customized...

'HERE IS ALL THE CODE

Private dt As DataTable

Private Sub MixedBarLine_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

BuildDataTable1()

Chart.ChartType = ChartType.Composite

Chart.BackColor = Color.Black

Chart.Data.ZeroAligned =

True

Chart.TitleTop.Text =

"Sales to Price Analysis"

Chart.TitleTop.FontColor = Color.Yellow

Chart.TitleTop.Font =

New Font("Arial", 14.0F)

Chart.TitleTop.HorizontalAlign = StringAlignment.Center

 

 

' Create the Chart Area

 

 

Dim area As ChartArea = New

ChartArea()

area.BoundsMeasureType = MeasureType.Percentage

area.Bounds =

New Rectangle(25, 10, 74, 90)

area.Border.Thickness = 0

 

 

Dim xAxis As AxisItem = New AxisItem()

 

 

Dim x2Axis As AxisItem = New AxisItem()

 

 

Dim yAxis As AxisItem = New AxisItem()

 

 

Dim y2Axis As AxisItem = New AxisItem()

 

 

Dim ColumnLayer As ChartLayerAppearance = New ChartLayerAppearance()

 

 

Dim LineLayer As ChartLayerAppearance = New ChartLayerAppearance()

 

 

Dim columnSeries As NumericSeries = New NumericSeries()

 

 

Dim lineSeries As NumericSeries = New NumericSeries()

 

xAxis.OrientationType = AxisNumber.X_Axis

 

 

'xAxis.Extent = 60

xAxis.DataType = AxisDataType.String

xAxis.SetLabelAxisType = SetLabelAxisType.GroupBySeries

xAxis.LineColor = Color.White

xAxis.Labels.FontColor = Color.White

xAxis.Labels.ItemFormatString =

"<ITEM_LABEL>"

xAxis.Labels.Layout.Behavior = AxisLabelLayoutBehaviors.Auto

xAxis.Labels.VerticalAlign = StringAlignment.Far

xAxis.Labels.HorizontalAlign = StringAlignment.Near

xAxis.Labels.Orientation = TextOrientation.Custom

xAxis.Labels.OrientationAngle = 45

xAxis.MajorGridLines.Visible =

False

x2Axis.OrientationType = AxisNumber.X_Axis

 

 

'x2Axis.Extent = 50

x2Axis.DataType = AxisDataType.String

x2Axis.LineColor = Color.Transparent

x2Axis.SetLabelAxisType = SetLabelAxisType.ContinuousData

yAxis.OrientationType = AxisNumber.Y_Axis

yAxis.Extent = 60

yAxis.TickmarkStyle = AxisTickStyle.Smart

yAxis.DataType = AxisDataType.Numeric

yAxis.LineColor = Color.White

yAxis.Labels.FontColor = Color.White

yAxis.Labels.ItemFormatString =

"<DATA_VALUE:$###,###,##0.# ->"

y2Axis.OrientationType = AxisNumber.Y2_Axis

y2Axis.Extent = 50

y2Axis.TickmarkStyle = AxisTickStyle.Smart

y2Axis.MajorGridLines.Visible =

False

y2Axis.DataType = AxisDataType.Numeric

y2Axis.LineColor = Color.White

y2Axis.Labels.FontColor = Color.White

y2Axis.Labels.ItemFormatString =

"<DATA_VALUE:- #0.00>"

columnSeries.Data.DataSource = dt

columnSeries.Data.LabelColumn =

"Label"

columnSeries.Data.ValueColumn =

"Dollars"

columnSeries.PEs.Add(

New PaintElement(Color.SteelBlue))

ColumnLayer.ChartType = ChartType.ColumnChart

ColumnLayer.Series.Add(columnSeries)

ColumnLayer.ChartArea = area

ColumnLayer.AxisX = xAxis

ColumnLayer.AxisY = yAxis

 

 

Dim columnApp As ColumnChartAppearance = CType(ColumnLayer.ChartTypeAppearance, ColumnChartAppearance)

columnApp.ColumnSpacing = 1

lineSeries.Data.DataSource = dt

lineSeries.Data.LabelColumn =

"Label"

lineSeries.Data.ValueColumn =

"Price"

lineSeries.PEs.Add(

New PaintElement(Color.White))

LineLayer.ChartType = ChartType.LineChart

LineLayer.Series.Add(lineSeries)

LineLayer.ChartArea = area

LineLayer.AxisX = x2Axis

LineLayer.AxisY = y2Axis

area.Axes.Add(xAxis)

area.Axes.Add(x2Axis)

area.Axes.Add(yAxis)

area.Axes.Add(y2Axis)

Chart.CompositeChart.ChartAreas.Add(area)

Chart.CompositeChart.ChartLayers.Add(ColumnLayer)

Chart.CompositeChart.ChartLayers.Add(LineLayer)

Chart.CompositeChart.Series.Add(columnSeries)

Chart.CompositeChart.Series.Add(lineSeries)

 

 

Dim AxisYLabel As BoxAnnotation = New BoxAnnotation()

AxisYLabel.Text =

"Dollars"

AxisYLabel.Border.Color = Color.Transparent

AxisYLabel.FillColor = Chart.BackColor

AxisYLabel.TextStyle.FontColor = Color.White

AxisYLabel.Location.Type = LocationType.Percentage

AxisYLabel.Location.LocationX = area.Bounds.X + 2

AxisYLabel.Location.LocationY = area.Bounds.Y - 2

Chart.Annotations.Annotations.Add(AxisYLabel)

 

 

Dim AxisY2Label As BoxAnnotation = New BoxAnnotation()

AxisY2Label.Text =

"Price"

AxisY2Label.Width = -1

AxisY2Label.TextStyle.HorizontalAlign = StringAlignment.Far

AxisY2Label.Border.Color = Color.Transparent

AxisY2Label.FillColor = Chart.BackColor

AxisY2Label.TextStyle.FontColor = Color.White

AxisY2Label.Location.Type = LocationType.Percentage

AxisY2Label.Location.LocationX = (area.Bounds.X + area.Bounds.Width) - 4

AxisY2Label.Location.LocationY = area.Bounds.Y - 2

Chart.Annotations.Annotations.Add(AxisY2Label)

Chart.Legend.DataAssociation = ChartTypeData.SplitData

 

 

' Add a Legend

 

 

Dim m_ChartLegend As New

CompositeLegend()

m_ChartLegend.ChartLayers.Add(ColumnLayer)

m_ChartLegend.ChartLayers.Add(LineLayer)

m_ChartLegend.BoundsMeasureType = MeasureType.Percentage

m_ChartLegend.Bounds =

New Rectangle(1, 10, 18, 40)

area.BoundsMeasureType = MeasureType.Percentage

area.Bounds =

New Rectangle(25, 10, 74, 90)

m_ChartLegend.PE.ElementType = PaintElementType.Gradient

m_ChartLegend.PE.FillGradientStyle = GradientStyle.Circular

m_ChartLegend.PE.Fill = Color.Yellow

m_ChartLegend.PE.FillStopColor = Color.Orange

m_ChartLegend.Border.CornerRadius = 10

m_ChartLegend.Border.Thickness = 0

m_ChartLegend.LabelStyle.FontSizeBestFit =

True

Chart.CompositeChart.Legends.Add(m_ChartLegend)

 

 

End Sub

 

 

Private Sub BuildDataTable1()

dt =

New DataTable()

dt.Columns.Add(

"Label", GetType(String))

dt.Columns.Add(

"Dollars", GetType(Double))

dt.Columns.Add(

"Price", GetType(Double))

dt.Rows.Add(

New Object() {"Sep", 1200000, 4.1})

dt.Rows.Add(

New Object() {"Oct", 1000000, 4.1})

dt.Rows.Add(

New Object() {"Nov", 1400000, 3.5})

dt.Rows.Add(

New Object() {"Dec", 4601000, 3.0})

dt.Rows.Add(

New Object() {"Jan", 1500000, 3.5})

dt.Rows.Add(N

ew Object() {"Feb", 1600000, 3.5})

dt.Rows.Add(

New Object() {"Mar", 2200000, 3.25})

 

 

End Sub