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 =
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
Chart.TitleTop.HorizontalAlign = StringAlignment.Center
' Create the Chart Area
ChartArea() area.BoundsMeasureType = MeasureType.Percentage area.Bounds =
area.BoundsMeasureType = MeasureType.Percentage
area.Bounds =
New Rectangle(25, 10, 74, 90) area.Border.Thickness = 0
area.Border.Thickness = 0
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 =
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
ColumnLayer.ChartType = ChartType.ColumnChart
ColumnLayer.Series.Add(columnSeries)
ColumnLayer.ChartArea = area
ColumnLayer.AxisX = xAxis
ColumnLayer.AxisY = yAxis
columnApp.ColumnSpacing = 1
lineSeries.Data.DataSource = dt
lineSeries.Data.LabelColumn =
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)
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)
AxisYLabel.Text =
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)
AxisY2Label.Text =
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
CompositeLegend() m_ChartLegend.ChartLayers.Add(ColumnLayer) m_ChartLegend.ChartLayers.Add(LineLayer) m_ChartLegend.BoundsMeasureType = MeasureType.Percentage m_ChartLegend.Bounds =
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 =
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 =
Chart.CompositeChart.Legends.Add(m_ChartLegend)
dt =
New DataTable() dt.Columns.Add(
dt.Columns.Add(
"Label", GetType(String)) dt.Columns.Add(
"Dollars", GetType(Double)) dt.Columns.Add(
"Price", GetType(Double)) dt.Rows.Add(
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
dt.Rows.Add(N
ew Object() {"Feb", 1600000, 3.5}) dt.Rows.Add(
New Object() {"Mar", 2200000, 3.25})
Any thoughts on this?
Hi,
Maybe you are looking for:
Please take a look at the modifications that I made in your sample for more details and let me know if you have any questions.
Sample:
Perfect! Thank you so much!