ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Issue in Gantt Chart
Posted by Daniel on Jan-05-2016 22:03
Hi Peter,

At the moment my gantt chart is scrolling as I expected but I have noted that I cannot
fill the green layer with data properly. As you know this chart has 2 layers. One is red
on the constant interval 0-256 and the second (the green layer) should be populated with
some values I am interested in. The idea is this green layer doesn't display those values
loaded in the UDT array ...Somewhere something goes wrong. Because my real data are
extracted from a database, I put here a sample (with 35 intervals) for a single layer
that I consider it relevant for my issue.

Private Type myUDT
    arr1() As Long
    arr2() As Long
End Type

Private StartData() As myUDT
Private labels() As String

Private Sub Form_Load()
    Set cd = New ChartDirector.API
    Chart.ViewportHeight = 0.04
    Call FillUDTArray
    Call createChart(Chart)
End Sub

Private Sub FillUDTArray()
    Dim tstArr(34) As Long, i As Long
    Dim green1() As Long, green2() As Long

    ReDim StartData(130)
    ReDim labels(130)

    For i = 0 To 34 'my data
        tstArr(i) = Choose(i + 1, 3, 103, 107, 111, 115, 119, 15, 123, 127, 131, 155, 19,
23, 27, 247, _
                    31, 35, 39, 7, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 11, 83, 87, 91, 95,
99)
    Next i

    ReDim green1(34)
    ReDim green2(34)

    For i = 0 To 34 'my data
        green1(i) = tstArr(i) - 3
        green2(i) = tstArr(i) + 1
    Next i

    StartData(0).arr1 = green1
    StartData(0).arr2 = green2

End Sub

Public Sub createChart(viewer As ChartViewer)
    Dim i As Long, w As Byte

    Dim c As XYChart
    Set c = cd.XYChart(600, 300, &HCCCCFF, &H0, 1)

    Call c.addTitle("Subnets usage - Orange Network", "timesbi.ttf", 15,
&HFFFFFF).setBackground(&H80)
    Call c.setPlotArea(80, 55, 460, 200, &HFFFFFF, &HEEEEEE, cd.LineColor, &HC0C0C0,
&HC0C0C0).setGridWidth(1, 1, 1, 1)

    Call c.swapXY
    Call c.yAxis().setDateScale(0, 256, 16) 'Show the same scale on the top and bottom
x-axes
    Call c.yAxis2().setLinearScale(0, 256, 16)
    'Call c.yAxis2().setLabelStyle("arialbd.ttf", 8)

    Call c.setYAxisOnRight

    Dim layer1() As BoxWhiskerLayer
    Dim layer2() As BoxWhiskerLayer

    'Copy the visible data we need into the view port data series
    Dim visBars As Long
    visBars = Int(Chart.ViewportHeight * UBound(labels) + 0.5) + 1

    Dim sIndex As Long
    sIndex = Int(viewer.ViewportTop * UBound(labels) + 0.5)

    ReDim layer1(visBars - 1)
    ReDim layer2(visBars - 1)
    ReDim visLabels(visBars - 1)
    w = Int(100 / (UBound(visLabels) + 1))

For i = 0 To visBars - 1
        visLabels(i) = labels(i + sIndex)
    Set layer1(i) = c.addBoxWhiskerLayer(StartData(i + sIndex).arr1, StartData(i +
sIndex).arr2, Empty, Empty, Empty, &HCC00, cd.SameAsMainColor,
cd.SameAsMainColor)
    Call layer1(i).setXData(Array(i, i, i, i))
    Call layer1(i).setDataWidth(w)

    Set layer2(i) = c.addBoxWhiskerLayer(Array(0), Array(256), Empty, Empty, Empty,
&HCC2200, cd.SameAsMainColor, cd.SameAsMainColor)
    Call layer2(i).setXData(Array(i))
    Call layer2(i).setDataWidth(w)
Next i

    Call c.xAxis().setLabels(visLabels)
    Set viewer.Chart = c
End Sub

So, why the green intervals are not inserted properly over the red layer ?!
Thank you in advance.

  Re: Issue in Gantt Chart
Posted by Peter Kwan on Jan-06-2016 00:12
Hi Daniel,

I have tried your code. In my case, everything looks normal.

I got a chart that contains 5 red bars. At the bottom red bar, there are 2 green segments.
This matches with your data.

Your data only contains green segments for the bottom bar, so the chart should only
contain green segments on the bottom bar. Your code provides the x-coordinates for 4
green bar segments, so only 4 green bar segments are drawn, which is from 0 to 4, 100 to
104, 104 to 108 and 108 to 112. Because the last 3 segments overlap, so the last 3 green
bar segments look like a longer bar segment.

If the above is not what you obtain, would you mind to attach the chart you obtain to help
me trouble-shoot the issue?

Regards
Peter Kwan

  Re: Issue in Gantt Chart
Posted by Daniel on Jan-06-2016 03:31
Attachments:
Hi Peter,
I have arranged data in the way you suggested to me but the green segments are not in a
contiunuum green bar. What I want to say is that I am looking to represent all those small
subnets (with the same size  4) on green layer. As you can see I should have as many
green segments as I loaded in array (35 respectively), even many of them will be merged.
What is wrong ? How could I load this set of data in my UDT so that to obtain with green
these free subnets ?
Below is the chart that could be exactly what you got when you run:
gantt.PNG

  Re: Issue in Gantt Chart
Posted by Peter Kwan on Jan-07-2016 01:25
Hi Daniel,

Yes, this is exactly what I see, and this should be correct according to your data.

Your data has provided the starting point of 35 segments, the ending point of 35 segments,
and the position of 4 segments. So only 4 segments are plotted, because your code has not
specify where to plot the other segments. The code that specifies where the segments are
plotted is:

Call layer1(i).setXData(Array(i, i, i, i))

The above means the x-coordinates of the first 4 segments (which are the vertical position
to plot the segments), and they are all at position i. It does not specify where should the
other segments be plotted. If all 35 segments should be plotted at position i, please create
an array with 35 elements, and store i in them.

Hope this can help.

Regards
Peter Kwan

  Re: Issue in Gantt Chart
Posted by Daniel on Jan-07-2016 20:41
Attachments:
Hi Peter,

Thanks for your support. I've channged the array in layer1.setXData according with my
number of segments and now everything seems to work well. However, there are some
issues on the view port side because my vertical scroll seem to change the labels in a
way
which is not synchronized with a natural step. I also suspect that from time to time the
scroll changing doesn't ensure a synchronization between labels and bars. To have an
overview of this issue I attach 3 pictures at first 3 steps generated by the scroll index in
this line :  sIndex = Int(viewer.ViewportTop * UBound(labels) + 0.5).

As you can see in the right corner, at first click on scrollbar control the sIndex is
increasing with 1 unit but second time it jump from 2 to 3 directly ... Also I would
expect when I scrolling from up to down to see the new values (subnets in my case)
appearing one by one on the latest bar in the bottom. Is it something wrong with those 2
routines involved in the chart view port calculation ?

Private Sub HScroll_Scroll() 'Set the view port based on the scroll bar
    Chart.ViewportTop = CDbl(HScroll.Value - HScroll.Min) / _
                            (HScroll.max - HScroll.Min) * (1 - Chart.ViewportHeight)
    Call Chart.updateViewPort(True, False)
End Sub

Private Sub Chart_ViewPortChanged(needUpdateChart As Boolean, needUpdateImageMap As Boolean)
    With HScroll
           .Enabled = Chart.ViewportHeight < 1
        If .Enabled Then
           .LargeChange = Int(Chart.ViewportHeight * (.max - .Min) + 0.99999999999)
           .SmallChange = Int(.LargeChange * 0.1 + 0.99999999999)
           .Value = CInt(Chart.ViewportTop / (1 - Chart.ViewportHeight) * (.max - .Min))
+ .Min
        End If
    End With
        Call createChart(Chart)
End Sub
Thank you.
Index0.PNG
Index1.PNG
Index2.PNG

  Re: Issue in Gantt Chart
Posted by Peter Kwan on Jan-08-2016 02:09
Hi Daniel,

When you click the scrollbar, the scroll bar will move. How much it moves depend on
the properties of the scrollbar and how you click on it. It does not depend on the
properties of the viewport. (The scrollbar is a Microsoft control, and the WinChartViewer
is a ChartDirector control, and they do not know each others.)

The HScroll_Scroll and Chart_ViewPortChanged are code that you need to write so that
the scrollbar can control the viewport (eg. when the scrollbar moves, the viewport
moves too), and also that the viewport can control the scrollbar (eg. when someone
drags on the chart to scroll the chart or zoom into the chart, the scrollbar should move
too).

In the sample code, the code in the HScroll_Scroll is written so that the viewport
reflects the scrollbar directly. The code in Chart_ViewPortChanged is written so that the
scrollbar reflects the viewport directly. However, because the Microsoft scrollbar must
use integers for its position, so there can be integer rounding error, which should be
negligible if you set the Max and Min value of the scroll bar so that their difference is a
large number.

The sample code also sets the amount of "large" scrollbar movement to whatever the
viewport height is, and the the amount of "small" scrollbar movement to 10% of the
"large" scrollbar movement. (The scrollbar can move "large" or "small" depending on
how the user clicks on it. Please refer to Microsoft documentation for details.)

For your current case, is the (Max - Min) is a large value (like in the sample code) so
that the integer rounding error is negligible? Is scrolling 10% of the viewport height
equal to 1 bar in your case? If you would like to scroll for 1 bar, you would need to
modify the code so that the "small" scrollbar movement is equal 1 bar in viewport units.

Hope this can help.

Regards
Peter Kwan