|
How to scroll a gantt chart verticaly ? |
Posted by Daniel on Dec-26-2015 18:58 |
|
Hi Peter,
As you already know from my previous post I created a gantt chart that has inside some
available IP subnet classes - in my case 1400, but the range could be variable slightly.
For chart loading with data I used an UDM array declared as
Private Type myUDT
arr1() As Long
arr2() As Long
End Type
Private StartData() As myUDT
For viewport I have adapted a piece of code published by you in the past but created for
a chart that is scrolled horizontaly and not verticaly.I don't know which line creates me
problems - could be Call layer2(i).setDataWidth(Int(100 * 4 / 5 / (UBound(visLabels) +
1))) ? - but for sure i am not able to scroll the chart verticaly even my UDT
StartData.arr1 and StartData.arr2 are loded properly. I cannot give you the subnet
classes because they are extracted from a database but I am confident that the issue is
related to how ViewPortChanged was built or even the sIndex variable : sIndex =
Int(viewer.ViewportLeft * UBound(labels) + 0.5). For a better understanding, below are
the lines that I have written so far in vb classic :
Private Sub HScroll_Scroll()
'Set the view port based on the scroll bar
Chart.ViewportLeft = CDbl(HScroll.Value - HScroll.Min) / (HScroll.max - HScroll.Min)
* (1 - Chart.ViewportWidth)
Call Chart.updateViewPort(True, False)
End Sub
Private Sub Chart_ViewPortChanged(needUpdateChart As Boolean,
needUpdateImageMap As Boolean)
With HScroll 'Set the horizontal scroll bar to reflect the current view port
.Enabled = Chart.ViewportWidth < 1
If .Enabled Then
.LargeChange = Int(Chart.ViewportWidth * (.max - .Min) + 0.99999999999)
.SmallChange = Int(.LargeChange * 0.1 + 0.99999999999)
.Value = CInt(Chart.ViewportLeft / (1 - Chart.ViewportWidth) * (.max - .Min)) +
.Min
End If
End With
Call CreateChart(Chart)
End Sub
Public Sub CreateChart(viewer As ChartViewer)
Dim i As Long
Dim c As XYChart
Set c = cd.XYChart(600, 300, &HCCCCFF, &H0, 1)
Call c.addTitle("Simple Gantt Chart Demo", "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.ViewportWidth * UBound(labels) + 0.5) + 1
Dim sIndex As Long
sIndex = Int(viewer.ViewportLeft * UBound(labels) + 0.5)
ReDim layer1(visBars - 1)
ReDim layer2(visBars - 1)
ReDim visLabels(visBars - 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 + sIndex, i + sIndex, i + sIndex, i + sIndex))
Call layer1(i).setDataWidth(Int(100 * 4 / 5 / (UBound(visLabels) + 1)))
Set layer2(i) = c.addBoxWhiskerLayer(Array(0), Array(256), Empty, Empty, Empty,
&HCC2200, cd.SameAsMainColor, cd.SameAsMainColor)
Call layer2(i).setXData(Array(i + sIndex))
Call layer2(i).setDataWidth(Int(100 * 4 / 5 / (UBound(visLabels) + 1)))
Next i
Call c.xAxis().setLabels(visLabels)
Set viewer.Chart = c
End Sub
Please note either the scrollbar control is set verticaly or horizontaly I need to see bars
of the chart in a vertical scrolling.
Thank you in advance for any clue.
|
Re: How to scroll a gantt chart verticaly ? |
Posted by Peter Kwan on Dec-29-2015 02:44 |
|
Hi Daniel,
I guess:
Call layer1(i).setXData(Array(i + sIndex, i + sIndex, i + sIndex, i + sIndex))
Call layer2(i).setXData(Array(i + sIndex))
should be:
Call layer1(i).setXData(Array(i, i, i, i))
Call layer2(i).setXData(Array(i))
Another issue is that your code is using ViewportWidth and ViewportLeft to control vertical
scrolling. Basically, the scrollbar updates ViewportWidth and ViewportLeft, and your code
scrolls the chart vertically based on the updated ViewportWidth and ViewportLeft. It should
work in your case. However, if you enables "drag to scroll", then the ViewportWidth and
ViewportLeft will only change if your drag the mouse horizontally on the chart. It means
dragging the mouse horizontally will cause the chart to scroll vertically, which is strange. To
avoid this, you may use ViewportHeight and ViewportTop instead. Also, your ChartViewer
may have the ScrollDirection property set to cvHorizontal. If this is the case, please change
it to cvVertical so it can respond to vertical dragging.
Hope this can help.
Regards
Peter Kwan |
Re: How to scroll a gantt chart verticaly ? |
Posted by Daniel on Jan-01-2016 09:44 |
|
Hi Peter,
Thank you for your valuable hint. Indeed, changing the lines as
Call layer1(i).setXData(Array(i, i, i, i))
Call layer2(i).setXData(Array(i))
fixed the chart vertical scolling. I took your suggestion and you are right, dragging the
mouse horizontally scrolls the chart vertically and the effect could be a bit unnatural. I
changed the ScrollDirection property to cvVertical and I added a new function so that to be
able to scroll the chart using the mouse wheel. Thank you so much for your support.
A happy new year. |
|