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

Message ListMessage List     Post MessagePost Message

  packPlotArea bugs
Posted by Zev Toledano on Jan-24-2011 05:23
I've narrowed down several tricky bugs to calling PackPlotArea and simplified my code in order to demonstrate all the bugs. I had to call PackPlotArea more than once to calculate sizes. I have since then figured out a better way to write my code without calling a few times, but here are the bugs FYI:

Private Sub Form_Load()
  Dim arr1() As Double, arr2() As Double, i As Long, arrStr() As String
  Dim cd As New ChartDirector.API, c As XYChart
  ReDim arr1(4): ReDim arr2(4): ReDim arrStr(4)
  For i = 0 To 4
    arr1(i) = i * 10
    arr2(i) = i * 5
    arrStr(i) = CStr(i)
  Next i
  Set c = cd.XYChart(210, 210)
  c.setPlotArea 0, 0, 210, 210
  Set br = c.addBarLayer(arr1, &H60000000 + RGB(0, 255, 0))
  c.packPlotArea 0, 0, 210, 210 ' < -- bug!!
  Call c.addLineLayer(arr2, &H60000000 + RGB(255, 0, 0)).setUseYAxis2(True)
  c.xAxis.setLabels arrStr
  c.yAxis2.setLabelFormat "{value|P2.,}"
  c.yAxis.setLabelFormat "${value|P2.,}"
  c.packPlotArea 0, 0, 210, 210
  Set ChartViewer1.Picture = c.makePicture()
End Sub

If you remove the first PackPlotArea call, then all is fine. Otherwise:
1. The line goes completely off scale relative to the second yaxis
2. The YAxis2 doesn't show anymore
3. The labelformat on the first yAxis is removed.

In short, it seems impossible to call packPlotArea before all data has been added. Isn't this a bug? If not, the code should do something about multiple calls IMO.

  Re: packPlotArea bugs
Posted by Peter Kwan on Jan-25-2011 02:19
Hi Zev,

You can call packPlotArea before you have added all the data. However, the packPlotArea will pack the plot area only based on the data and configuration it knows about. So in your case, packPlotArea will not consider the line layer, and will not consider the y-axis label format, as they are added after packPlotArea.

In other words, packPlotArea acts immediately when you call it. This is the normal behaviour of packPlotArea.

In many applications, people will call packPlotArea, and then based on the result (the resuting plot area position and axis scale can be queried using the ChartDirector API), add more things to the chart. If adding more data to the chart after packPlotArea can change the plot area position and/or axis scale, then one can never adding any data  based on the plot area position and/or axis scale.

If you need the plot area position to be based on all the data, you can always call packPlotArea after adding all the data.

Hope this can help.

Regards
Peter Kwan

  Re: packPlotArea bugs
Posted by Zev Toledano on Jan-25-2011 02:34
I understand what you said which is why I had to improve my code. But regardless of what I am trying to do, I was just informing you of bugs that occur you call PackPlotArea twice. It's not that the plotarea doesn't contain data that I did not yet add. It's that even after the SECOND call to PackPlotArea the graph has many problems, as listed in my original post.

Just run my code and you will see what I mean in the final graph.

  Re: packPlotArea bugs
Posted by Peter Kwan on Jan-25-2011 04:49
Hi Zev,

I see what you mean now.

Unluckily, the axis scale in ChartDirector currently can only be laid out once.

The packPlotArea call will automatically layout the axes in case they have not already been laid out, as it needs the axis scale and labels in order to determine the plot area size. So after calling packPlotArea for the first time, the axis scale is fixed, and any call to configure the axis scale or label formats will have no effect.

So whereas you can call packPlotArea multiple times to resize the plot area (such as to pack the plot area to a different size), the axis scale will not be changed.

Normally, we do not expect people to call packPlotArea multiple times, as packPlotArea is intended to be used for finalizing the plot area size. To give ChartDirector an initial estimate of the plot area size (which is subjected to change later), you may use setPlotArea instead of packPlotArea.

Hope this can help.

Regards
Peter Kwan

  Re: packPlotArea bugs
Posted by Zev Toledano on Jan-25-2011 05:02
Then I guess if the axis scale can't be reset using some function call, then the only problem is that this needs to be explained in the documentation. Thanks for your help.

  Re: packPlotArea bugs
Posted by Peter Kwan on Jan-25-2011 16:20
Hi Zev,

Thanks a lot for your suggestion. I perfectly agree with you. We will update our documentation to explain about it.

Regards
Peter Kwan