|
Two issues |
Posted by Daniel on Sep-04-2014 23:12 |
|
Hello Peter,
I have 2 issues in ChartDirector and I do not how to solve them. I use a XYChart with 2
layers and at a certain level on yAxis I added a red mark (that is a threshold). These 2
DataSet has a name that appears on the top of the chart. The idea is I want to add on the
top of the chart some info regarding this threshold but I failed. As you know, a mark
doesn't have a DataSet associated but it is simply referenced as follow :
Set mark = c.yAxis().addMark(150, &HFF0000, "Target", "arial.ttf", 8). The text "Target"
is present right on the mark line and cannot be moved on the top, near of other 2 labels of
my layers... Do you think is possible to insert this mark text on the top side ? To
understand easier I attached 2 samples : one is created in excel (which is the template)
and other is mine, created with chartdirector.
The second issue is my customer wants to have displayed the latest data values right on
the end of the line (like in my doc). I really don't have any idea how to realize this in
chartdirector. Inspired by your demo I tried Call layer.setAggregateLabelFormat("{value}")
but it doeasn't seem to work. Any idea? Thank you in advance.
|
Re: Two issues |
Posted by Peter Kwan on Sep-05-2014 06:12 |
|
Hi Daniel,
For the first issue, you my add an empty layer or an empty dataset to your chart. In this
way, you can add an extra legend icon to the chart. Another method is to use
Legend.addKey to add an extra icon to the legend box. For example:
Call c.getLegend().addKey("Target", &HFF0000, 2)
You may also want to use LegendBox.setLineStyleKey so that the icon will look like a line
for line layers, rather than a box:
Call c.getLegend().setLineStyleKey()
To create the latest data values on the right y-axis, you may use Axis.addMark, and set
the mark line to transparent, so that only the text is visible. It is like:
'Set the right y-axis the same scale as the left y-axis, so that you can addMark to the
'right y-axis
Call c.syncYAxis()
'Make the default right y-axis labels invisible
Call c.yAxis2().setColors(cd.Transparent, cd.Transparent)
'Create a mark at the value of the last data point, with a transparent line and black text
Call c.yAxis2().addMark(myData(Ubound(myData)), -1,
myData(Ubound(myData))).setMarkColor(cd.Transparent, &H000000, cd.Transparent)
Hope this can help.
Regards
Peter Kwan |
Re: Two issues |
Posted by Daniel on Sep-05-2014 17:58 |
|
Hi Peter,
All your suggestions worked perfectly fine. However, I have a few new questions. In the
line Call c.getLegend().addKey("Target", &HFF0000, 2) you set the line width as 2 but I
think it is not necessary as long as I have somewhere in my code Call
mark.setLineWidth(2). After that you suggest I could replace in the legend boxes with lines
using Call c.getLegend().setLineStyleKey. It worked, but for all layers. Maybe it is tricky
but I just want to know if is it possible to have displayed in the legend boxes for those 2
layers and line for the trend only ? Other question : how do you describe the syncYAxis
method ? Is it always necessary when we want to include a secondary Y axis (yAxis2) ?
Finally, I have managed to create a mark at the last data point, with a transparent line and
black text but I just wonder if the fonts from the text could be bold. No textStyle method
in conjunction with setMarkColor ? Thank you.
PS. I think you noted I work in VB6, do you have any idea why my IDE doesn't access the
ChartDirector help whenever I search for a CD method or property (when I push F1) ? |
Re: Two issues |
Posted by Peter Kwan on Sep-06-2014 03:51 |
|
Hi Daniel,
One method you can add an icon of any shape in the legend box is to simply add an
empty scatter layer with the shape you want. So for your case, you can first disable the
automatic legend entry of your line layer, then add empty scatter layers for the symbol
you want. To disable the automatic legend entry in your line layer, simply use an empty
name when you add the data set. If you must provide a name to the data set (eg. for
the purpose of creating tooltips), you may use Layer.setLegendOrder to disable the
automatic legend entry. It is like:
Call myLineLayer.setLegendOrder(cd.NoLegend)
'add a legend entry using a red square symbol 9 pixels in size
Call c.addScatterLayer(Nothing, Nothing, "My Line 1", cd.SquareShape, 9, &Hff0000)
.... add more entries if necessary ....
For the syncYAxis method, we need that because we are adding the mark to the right y-
axis, but the right y-axis does not have scale (as I guess it is not used by any data set
in your code). ChartDirector supports multiple independent y-axes, and it will not
automtically assume all y-axes are of the same scale. So if you add a mark at 123 to the
right y-axis, ChartDirector would not know where is 123 on the right y-axis. That's why
we need to use syncYAxis to tell ChartDirector that the right y-axis is the same as the
left y-axis.
The syncYAxis is not necessary if the two y-axes are independent, such as when the
first line is using the left y-axis, and the second line is using the right y-axis. See the
"Dual Y-Axis" sample code for an example. The syncYAxis is needed is the two y-axes are
dependent, such as if the two y-axes are the same, or has some fixed linear relationship
(such as one y-axis denote length in cm, and the other y-axis denote length in inch, and
so they have the relationship y2 = y * 2.54).
As according to the ChartDirector documentation, the Mark object is a subclass of the
TextBox object, so it supports all TextBox methods, including methods to change the
font, background color, etc.. In fact, you can directly specify the font when calling
addMark:
Call c.yAxis2().addMark(myData(Ubound(myData)), -1, myData(Ubound(myData)),
"Arial Bold", 10).setMarkColor(cd.Transparent, &H000000, cd.Transparent)
For the help files, the VB6 is a technology developed in the last century, and at that
time, VB6 IDE does not support integrating third party help. So when you press F1, the
VB6 IDE can only search for its own help file, which would not contain ChartDirector
specific information. For ChartDirector, you would need to open the CHM documentation
that comes with ChartDirector.
Hope this can help.
Regards
Peter Kwan |
Re: Two issues |
Posted by Daniel on Sep-06-2014 23:48 |
|
Hi Peter,
Thank you very much for your detailed response. Now is clear to me how to use these methods within my charts. ChartDirector is a great library and you make a good job providing us your valuable support.
Kind regards,
Daniel |
|