Hello,
What I was just looking for the combination of a Column and Line chart where half y axis is used. I must be dynamic, because I never know what type of chart the user will choose and over how many signals it will go. When I try the example, the result is not correct. It allows the Series F not see. This is a part of my code used.
Thanks in advance.
'Line chart '***************************************************************************Dim axisX2 As New AxisItem()axisX2.OrientationType = AxisNumber.X2_AxisaxisX2.DataType = AxisDataType.NumericaxisX2.Labels.ItemFormatString = ""axisX2.Labels.Orientation = TextOrientation.VerticalLeftFacingaxisX2.Extent = 40myChartArea.Axes.Add(axisX2)With axisY.axisNumber = AxisNumber.Y_Axis.RangeType = AxisRangeType.Automatic.DataType = AxisDataType.Numeric.Labels.ItemFormatString = "".Labels.Orientation = TextOrientation.Custom.Extent = 40End WithDim app As New LineChartAppearanceapp.NullHandling = NullHandling.DontPlotDim seriesC As XYSeries = GetXYSeriesBound()Dim seriesD As XYSeries = GetXYSeriesUnBound()Me.UltraChart1.CompositeChart.Series.Add(seriesC)Me.UltraChart1.CompositeChart.Series.Add(seriesD)' Customize the series colors.seriesC.PEs.Add(New PaintElement(Drawing.Color.Green))seriesD.PEs.Add(New PaintElement(Drawing.Color.Blue))Dim myScatterLayer As New ChartLayerAppearance()myScatterLayer.ChartType = ChartType.ScatterChartCType(myScatterLayer.ChartTypeAppearance, ScatterChartAppearance).ConnectWithLines = TruemyScatterLayer.ChartArea = myChartAreamyScatterLayer.AxisX = axisX2myScatterLayer.AxisY = axisYmyScatterLayer.Series.Add(seriesC)myScatterLayer.Series.Add(seriesD)Me.UltraChart1.CompositeChart.ChartLayers.Add(myScatterLayer)' Add the second layer to the legend.myLegend.ChartLayers.Add(myScatterLayer)'Column chart'***************************************************************************Dim axisY2 As New AxisItem()Dim axisX As New AxisItem()axisX.OrientationType = AxisNumber.X_AxisaxisX.DataType = AxisDataType.StringaxisX.SetLabelAxisType = SetLabelAxisType.GroupBySeriesaxisX.Labels.ItemFormatString = "<ITEM_LABEL>"axisX.Labels.Orientation = TextOrientation.VerticalLeftFacingaxisY.OrientationType = AxisNumber.Y_AxisaxisY.DataType = AxisDataType.NumericaxisY.Labels.ItemFormatString = "<DATA_VALUE:0.#>"myChartArea.Axes.Add(axisX)myChartArea.Axes.Add(axisY)axisY2.OrientationType = AxisNumber.Y2_AxisaxisY2.DataType = AxisDataType.NumericaxisY2.Labels.ItemFormatString = "<DATA_VALUE:0.#>"myChartArea.Axes.Add(axisY2)Dim myColumnLayer As New ChartLayerAppearance()Dim myColumnLayer1 As New ChartLayerAppearance()myColumnLayer.ChartType = ChartType.ColumnChartmyColumnLayer1.ChartType = ChartType.ColumnChartmyColumnLayer.ChartArea = myChartAreamyColumnLayer1.ChartArea = myChartAreamyColumnLayer.AxisX = axisXmyColumnLayer.AxisY = axisYmyColumnLayer1.AxisX = axisXmyColumnLayer1.AxisY2 = axisY2Dim seriesA As NumericSeries = GetNumericSeriesBound()Dim seriesB As NumericSeries = GetNumericSeriesUnBound()Dim seriesF As NumericSeries = GetNumericSeriesBound1()myColumnLayer.Series.Add(seriesA)myColumnLayer1.Series.Add(seriesB)myColumnLayer.Series.Add(seriesF)Me.UltraChart1.CompositeChart.Series.Add(seriesA)Me.UltraChart1.CompositeChart.Series.Add(seriesB)Me.UltraChart1.CompositeChart.Series.Add(seriesF)myColumnLayer.SwapRowsAndColumns = TrueMe.UltraChart1.CompositeChart.ChartLayers.Add(myColumnLayer)Me.UltraChart1.CompositeChart.ChartLayers.Add(myColumnLayer1)myLegend.ChartLayers.Add(myColumnLayer)myLegend.Bounds = New Rectangle(0, 75, 20, 25)myLegend.BoundsMeasureType = MeasureType.PercentagemyLegend.PE.ElementType = PaintElementType.GradientmyLegend.PE.FillGradientStyle = GradientStyle.ForwardDiagonalmyLegend.PE.Fill = Drawing.Color.CornflowerBluemyLegend.PE.FillStopColor = Drawing.Color.TransparentmyLegend.Border.CornerRadius = 10myLegend.Border.Thickness = 0Me.UltraChart1.CompositeChart.Legends.Add(myLegend)Me.UltraChart1.InvalidateLayers()
End Sub Private Shared Function GetData() As DataTable Dim table As New DataTable() table = New DataTable table.Columns.Add("Label Column", GetType(String)) table.Columns.Add("Waarde Column", GetType(Double)) table.Columns.Add("Another Waarde Column", GetType(Double)) table.Rows.Add(New Object() {"2000", 1.0, 3.0}) table.Rows.Add(New Object() {"2001", 2.0, 2.0}) table.Rows.Add(New Object() {"2002", 3.0, 1.0}) table.Rows.Add(New Object() {"2003", 4.0, 2.0}) table.Rows.Add(New Object() {"2004", 5.0, 3.0}) Return table End Function Private Shared Function GetNumericSeriesUnBound() As NumericSeries Dim series As New NumericSeries() series.Label = "Series B" ' this code populates the series using unbound data series.Points.Add(New NumericDataPoint(5.0, "2000", False)) series.Points.Add(New NumericDataPoint(4.0, "2001", False)) series.Points.Add(New NumericDataPoint(3.0, "2002", False)) series.Points.Add(New NumericDataPoint(2.0, "2003", False)) series.Points.Add(New NumericDataPoint(1.0, "2004", False)) Return series End Function Private Function GetXYSeriesUnBound() As XYSeries Dim series As New XYSeries() series.Label = "Hello" ' this code populates the series using unbound data series.Points.Add(New XYDataPoint(1.0, 1.0, "2000", False)) series.Points.Add(New XYDataPoint(2.0, 2.0, "2001", False)) series.Points.Add(New XYDataPoint(3.0, 3.0, "2002", False)) series.Points.Add(New XYDataPoint(4.0, 4.0, "2003", False)) series.Points.Add(New XYDataPoint(5.0, 5.0, "2004", False)) Return series End Function Private Function GetXYSeriesBound() As XYSeries Dim series As New XYSeries() series.Label = "Series C" ' this code populates the series from an external data source Dim table As DataTable = GetData() series.Data.DataSource = table series.Data.LabelColumn = "Label Column" series.Data.ValueXColumn = "Waarde Column" series.Data.ValueYColumn = "Another Waarde Column" Return series End Function Private Shared Function GetNumericSeriesBound() As NumericSeries Dim series As New NumericSeries() series.Label = "Series A" ' this code populates the series from an external data source Dim table As DataTable = GetData() series.Data.DataSource = table series.Data.LabelColumn = "Label Column" series.Data.ValueColumn = "Waarde Column" Return series End Function Private Shared Function GetNumericSeriesBound1() As NumericSeries Dim series As New NumericSeries() series.Label = "Series F" ' this code populates the series from an external data source Dim table As DataTable = GetData() series.Data.DataSource = table series.Data.LabelColumn = "Label Column" series.Data.ValueColumn = "Another Waarde Column" Return series End Function
End Sub
Private Shared Function GetData() As DataTable Dim table As New DataTable() table = New DataTable table.Columns.Add("Label Column", GetType(String)) table.Columns.Add("Waarde Column", GetType(Double)) table.Columns.Add("Another Waarde Column", GetType(Double)) table.Rows.Add(New Object() {"2000", 1.0, 3.0}) table.Rows.Add(New Object() {"2001", 2.0, 2.0}) table.Rows.Add(New Object() {"2002", 3.0, 1.0}) table.Rows.Add(New Object() {"2003", 4.0, 2.0}) table.Rows.Add(New Object() {"2004", 5.0, 3.0}) Return table End Function Private Shared Function GetNumericSeriesUnBound() As NumericSeries Dim series As New NumericSeries() series.Label = "Series B" ' this code populates the series using unbound data series.Points.Add(New NumericDataPoint(5.0, "2000", False)) series.Points.Add(New NumericDataPoint(4.0, "2001", False)) series.Points.Add(New NumericDataPoint(3.0, "2002", False)) series.Points.Add(New NumericDataPoint(2.0, "2003", False)) series.Points.Add(New NumericDataPoint(1.0, "2004", False)) Return series End Function Private Function GetXYSeriesUnBound() As XYSeries Dim series As New XYSeries() series.Label = "Hello" ' this code populates the series using unbound data series.Points.Add(New XYDataPoint(1.0, 1.0, "2000", False)) series.Points.Add(New XYDataPoint(2.0, 2.0, "2001", False)) series.Points.Add(New XYDataPoint(3.0, 3.0, "2002", False)) series.Points.Add(New XYDataPoint(4.0, 4.0, "2003", False)) series.Points.Add(New XYDataPoint(5.0, 5.0, "2004", False)) Return series End Function Private Function GetXYSeriesBound() As XYSeries Dim series As New XYSeries() series.Label = "Series C" ' this code populates the series from an external data source Dim table As DataTable = GetData() series.Data.DataSource = table series.Data.LabelColumn = "Label Column" series.Data.ValueXColumn = "Waarde Column" series.Data.ValueYColumn = "Another Waarde Column" Return series End Function Private Shared Function GetNumericSeriesBound() As NumericSeries Dim series As New NumericSeries() series.Label = "Series A" ' this code populates the series from an external data source Dim table As DataTable = GetData() series.Data.DataSource = table series.Data.LabelColumn = "Label Column" series.Data.ValueColumn = "Waarde Column" Return series End Function Private Shared Function GetNumericSeriesBound1() As NumericSeries Dim series As New NumericSeries() series.Label = "Series F" ' this code populates the series from an external data source Dim table As DataTable = GetData() series.Data.DataSource = table series.Data.LabelColumn = "Label Column" series.Data.ValueColumn = "Another Waarde Column" Return series End Function
Me.UltraChart1.ChartType = ChartType.Composite myChartArea = Me.UltraChart1.CompositeChart.ChartAreas(0) Me.UltraChart1.CompositeChart.ChartAreas.Add(myChartArea)
Sub CreateChart()
Dim myLegend As New CompositeLegend() Dim myChartArea As New ChartArea() Dim axisY As New AxisItem()
I don't really understand what your expectation is. Here's what I get when I run the code you have provided. Is the image not correct? And if so, how? If you intend to show all 3 numeric series, you should add them to the same column layer. Also, seriesF appears to be visible.
Hello Max,
I am one step closer to the chart that they asked.
What am I doing wrong. I try to add a second layer (type = Column chart) because this will used the second y-axes. But then I see this Wrong.png is not good it should be Ok.png)
Johan
If you want multiple column series to be grouped together you should put them on the same column layer. I advise against using multiple axes for the series that have to be grouped. In fact if you do use 2 y axes for the column series, getting the grouping to work will be difficult.
If you absolutely have to have grouped columns with different y axes, you will have to create some empty series for each layer, for example:columnlayer1 will have one series with real values and one with empty values. So will columnlayer2, but this time the first series will have empty values and the second will have real values. Also, all the series need to have the same number of points to look right. The second layer will draw over the first layer, and the real series will overlay the empty series.
I have two problems left. The legend does not appear and the possibility of turning the labels on the x-axis is not possible. Can you help me with this.
Tanks in advance.
CompositeLegend
legend.ChartLayers.Clear()
()
dt.Columns.Add(
))
dt.Rows.Add(
})
.Composite
.UltraChart1.CompositeChart.ChartAreas.Add(area)
.X_Axis)
xAxisColumn.DataType =
.[String]
xAxisColumn.SetLabelAxisType =
.GroupBySeries
xAxisColumn.Labels.ItemFormat =
.ItemLabel
xAxisColumn.Labels.ItemFormatString =
""
'Changing orientation labels does not works
xAxisColumn.Labels.Orientation =
.VerticalLeftFacing
xAxisColumn.Labels.VerticalAlign =
.Near
'xAxisColumn.Labels.OrientationAngle = 40
xAxisLine.DataType =
xAxisLine.SetLabelAxisType =
.ContinuousData
xAxisLine.Labels.ItemFormat =
xAxisLine.Labels.ItemFormatString =
xAxisLine.Labels.Orientation =
xAxisLine.Labels.VerticalAlign =
'xAxisLine.Labels.OrientationAngle = 40
.Y_Axis)
yAxis.RangeType =
.Automatic
yAxis.TickmarkStyle =
.DataInterval
yAxis.RangeMax = 20
yAxis.RangeMin = 0
yAxis.DataType =
.Numeric
yAxis.Labels.ItemFormatString =
"<DATA_VALUE>"
yAxis.Labels.ItemFormat =
.DataValue
yAxis.Labels.Orientation =
.Custom
yAxis.Labels.OrientationAngle = 40
.Y2_Axis)
yAxis2.OrientationType =
.Y2_Axis
yAxis2.DataType =
yAxis2.RangeType =
yAxis2.TickmarkStyle =
yAxis2.RangeMax = 10
yAxis2.RangeMin = 0
yAxis2.Extent = 40
yAxis2.Labels.ItemFormatString =
"<DATA_VALUE:>"
yAxis2.Labels.Orientation =
yAxis2.Labels.OrientationAngle = 40
area.Axes.Add(xAxisColumn)
area.Axes.Add(xAxisLine)
area.Axes.Add(yAxis)
area.Axes.Add(yAxis2)
seriesColumn.Data.DataSource = dt
seriesColumn.Data.LabelColumn =
"col5"
seriesColumn.Data.ValueColumn =
"col3"
seriesColumn2.Data.DataSource = dt
seriesColumn2.Data.LabelColumn =
seriesColumn2.Data.ValueColumn =
"col4"
seriesLine.Data.DataSource = dt
seriesLine.Data.LabelColumn =
seriesLine.Data.ValueColumn =
"col1"
seriesLine1.Data.DataSource = dt
seriesLine1.Data.LabelColumn =
seriesLine1.Data.ValueColumn =
"col2"
() {seriesLine, seriesLine1, seriesColumn, seriesColumn2})
columnLayer.AxisX = xAxisColumn
columnLayer.AxisY = yAxis
columnLayer.ChartArea = area
columnLayer.ChartType =
.ColumnChart
columnLayer1.ChartType =
columnLayer1.AxisX = xAxisColumn
columnLayer1.AxisY = yAxis2
columnLayer1.ChartArea = area
columnLayer.Series.Add(seriesColumn)
'This change to two 2 Y-axis gives problems
'Problem solved by Max Rivlin!!
'columnLayer1.Series.Add(seriesColumn2)
columnLayer.Series.Add(seriesColumn2)
columnLayer.SwapRowsAndColumns =
True
columnLayer1.SwapRowsAndColumns =
lineLayer.ChartType =
.LineChart
)
lineApp.NullHandling =
.DontPlot
lineLayer1.ChartType =
lineApp1.NullHandling =
lineLayer.AxisX = xAxisLine
lineLayer.AxisY = yAxis2
lineLayer.ChartArea = area
lineLayer1.AxisX = xAxisLine
lineLayer1.AxisY = yAxis
lineLayer1.ChartArea = area
lineLayer.Series.Add(seriesLine)
lineLayer1.Series.Add(seriesLine1)
.UltraChart1.CompositeChart.ChartLayers.Add(columnLayer)
.UltraChart1.CompositeChart.ChartLayers.Add(columnLayer1)
.UltraChart1.CompositeChart.ChartLayers.Add(lineLayer)
.UltraChart1.CompositeChart.ChartLayers.Add(lineLayer1)
'Adding a Legend, works not
legend.ChartLayers.Add(columnLayer)
legend.ChartLayers.Add(lineLayer)
legend.ChartLayers.Add(lineLayer1)
legend.BoundsMeasureType =
.Percentage
legend.Bounds =
(25, 5, 50, 15)
(0, 20, 100, 80)
.UltraChart1.ColumnChart.SeriesSpacing = 1
Looks like in this code sample you're using series labels instead of item labels (a label represents a group of columns, instead of individual column). Use this line of code to set label orientation:xAxisColumn.Labels.SeriesLabels.Orientation = TextOrientation.VerticalLeftFacing
As for the legend, you forgot to add it to the chart control. You should also set a label on each of your series; the legend won't show the series without a label.seriesColumn.Label = "column series 1"seriesColumn2.Label = "column series 2"seriesLine.Label = "line series 1"seriesLine1.Label = "line series 2"legend.Bounds = New Rectangle(25, 5, 50, 15)
UltraChart1.CompositeChart.Legends.Add(legend)
Max,
Thank you so much I adjust my code.