|
MultiChart image not shown |
Posted by Peter W on Aug-19-2018 04:37 |
|
Hi there,
I am trying to show several bar chart images in MultiChart. However, only the first bar chart image shows up, and the other images are missing (the plot areas are still there). Part of the code is listed below. Could any one help, please?
MChart = New MultiChart(1200, 250 * NumLine)
' Define each XY Chart object size, 1200 x 250 pixels
Dim width As Integer = 1200
Dim height As Integer = 250
For NL As Integer = 0 To NumLine - 1
' Create a XYChart object
Dim CT As XYChart = New XYChart(width, height)
' Insert XYChart
MChart.addChart(0, 250 * NL, CT)
' XYChart location (top left corner)
Dim StartLocX As Integer = 25
Dim StartLocY As Integer = 5 + 250 * NL
' Set the plotarea
CT.setPlotArea(StartLocX, StartLocY, width - StartLocX - 10, height - 30)
CT.yAxis.setLinearScale(0, 1)
' Add a stacked bar layer and set the layer 3D depth to 0 pixels
Dim layer As BarLayer = CT.addBarLayer2(Chart.Stack, 0)
' Set the labels on the x axis
Dim Indiv1, Indiv2 As Integer
Indiv1 = NL * NumIndivPlot
Indiv2 = Math.Min((NL + 1) * NumIndivPlot, NumberIndiv)
Dim labels(NumIndivPlot - 1) As String
For i As Integer = Indiv1 To Indiv2 - 1
labels(i - Indiv1) = i + 1
Next
If NumIndivPlot <= 50 Then CT.xAxis().setLabels(labels)
' Add data sets to the bar layer (red FF0000; Green 00FF00; Blue 0000FF)
Dim data0(NumIndivPlot - 1) As Double
For i As Integer = 0 To NumPop - 1
For j As Integer = Indiv1 To Indiv2 - 1
data0(j - Indiv1) = data(j, i)
Next
Dim cc As String = Form6.SelectedColor(i).ToArgb().ToString("X6")
cc = "&H" & cc.Substring(2)
layer.addDataSet(data0, cc, "P" & (i + 1).ToString)
Next
' The width of the bars (or bar groups for multi-bar layers) in pixels.
layer.setBarWidth(5)
' Set bar gap (-1 for no gap, 0 for a small gap)
layer.setBarGap(-1)
' Remove bar border using "-1", blackColor with "1"
Dim iB As Integer = 1
If NumIndivPlot > 50 Then iB = -1
layer.setBorderColor(iB)
Next
WinChartViewer1.Image = MChart.makeImage() |
Re: MultiChart image not shown |
Posted by Peter Kwan on Aug-23-2018 18:36 |
|
Hi Peter W,
I think there may be a mistake in the following line:
Dim StartLocY As Integer = 5 + 250 * NL
It should be:
Dim StartLocY As Integer = 5
It is because the StartLocY is used in the CT object:
CT.setPlotArea(StartLocX, StartLocY, width - StartLocX - 10, height - 30)
so its value should be relative to the CT object, not relative to the MChart object.
For the bar formatting, I also found some issues with the following code, as your bar chart is not a Multi-Bar chart, "1" is not the black color, and "-1" may not mean transparent or no gap. The setBarWidth contradicts with the setBarGap. (If you specify no bar gap, then you can also specify the bar width, because the bar width must be adjusted to ensure no bar gap.)
' The width of the bars (or bar groups for multi-bar layers) in pixels.
layer.setBarWidth(5)
' Set bar gap (-1 for no gap, 0 for a small gap)
layer.setBarGap(-1)
' Remove bar border using "-1", blackColor with "1"
Dim iB As Integer = 1
If NumIndivPlot > 50 Then iB = -1
layer.setBorderColor(iB)
I think it should be:
'No Bar Gap
layer.setBarGap(Chart.TouchBar)
' Remove bar border using Chart.Transparent, blackColor with &H000000
Dim iB As Integer = &H000000
If NumIndivPlot > 50 Then iB = Chart.Transparent
layer.setBorderColor(iB)
Hope this can help.
Regards
Peter Kwan |
|