|
How to insert a second xAxis ? |
Posted by Daniel on May-21-2017 07:31 |
|
Hello Peter,
I use in VB6 a scrollable chart where I want to display values of at least 4 years and I preffer to set as visible date of x Axis on 90 days (~3 months). The real date format - as it is stored - is dd.mm.yyyy. My issue is all these labels have an inconvenient lenght that make them to be overwritten one with other. Due to this format limitation I kept as label only the day but I would like to insert a second X axis where to highlight the month and year. Of course, this secondary X axis should be scrollable as well, meaning each month/year should be in concordance with labels (days) from first X axis. Is it possible ? I saw that you made something very closed of this scenario in your demo, excepting the fact your month/year labels updating were not scrollable. To have a more clear idea about my chart I insert a print screen below. Thank you in advance.
|
Re: How to insert a second xAxis ? |
Posted by Peter Kwan on May-23-2017 04:04 |
|
Hi Daniel,
One important point I would like to know is exactly what you meant by "date". If something is really stored as dd.mm.yyyy, it is unlikely to be a date in the VB6 language (although it can be a date in human language). It is likely to be a text string in VB6. In VB6, a date is a data type called "Date". If can be created using the DateSerial function. If the data comes from a database and it is really a date to the database (the database schema defines the column to be of Date or Timestamp or similar type), most database drivers will read them into VB6 as the Date data type.
If the dates are really dates to VB6 and are used as x-coordinates (passed to the chart object using Layer.setXData), ChartDirector can automatically generate x-axis labels with spacing so that they do not overlap. The label format can be configured so that it will display the month only at the first date or a month, and the month can be configured to display in a second line. An example is the "Zooming and Scrolling Demonstration" sample code:
http://www.advsofteng.com/doc/cdcom.htm#zoomscrolldemo.htm
The above features only work for dates to VB6. If they are text strings instead, they are just names and have no meaning to VB6 or ChartDirector. In this case, you would need to determine how to display them with your own code.
To create a second x-axis, you can use XYChart.addAxis. There is an example for adding extra y-axis as follows. You can use the same method to add extra x-axis as well.
http://www.advsofteng.com/doc/cdcom.htm#multiaxes.htm
After adding the x-axis, you can set the labels so that there is a month label only at the start of the month, and the other labels set to empty strings.
Regards
Peter Kwan |
Re: How to insert a second xAxis ? |
Posted by Daniel on May-23-2017 17:11 |
|
Hello Peter,
Thank you for your response. When I mentioned the dd.mm.yyyy I wanted to be more clear what kind of date format I have backside of my labels...Of course it is not a string but a Format that is usual in the programming world. So my dates are dates and they are extracted from a database where in the db schema are declared as date type, respectively dd-mmm-yyyy. However, in the chart I preferred to declare the label array as string because honestly I don't see any advantage in keeping the original format. Is there any? I really don't understand why do you say that labels, as names, "have no meaning to VB6 or ChartDirector"... In the ChartDirector sample - "Zooming and Scrolling Demonstration" - you avoided the overlapping effect because you displayed months only but my customers wants to see the specific (numeric) days inside each month. Furthermore, having dates starting with 2012 it is necessary to point out the year after each 12 months. I want to say that you cannot keep both month,years and days on the same axis due to the fact either you increase the distance among label points on axis or you will have a crowded axis with very close labels. For this reason I considered that months and years should be placed on a second x-axis but keeping sync with first. Because your I received your response a bit late meanwhile I found in your samples an interesting trick based on CDML that solved my issue. The loop below considering the month&year will be displayed whenever day 12 or 13 occurs...
You could ask why 12 or 13, that is because I preferred to set the label step to 2 and sometimes 12 or 13 is missing but never both ... Do you have other ideas? Ideally would be to mark somehow the ticks on x-axis where each new month is starting, but I dont know how .
Thank you for your support.
For i = 0 To N
a = Format$(nur2G(0, i + s), "dd") 'day
If a = "12" Or a = "13" Then
b = Format$(nur2G(0, i + s), "mmmm yyyy") 'month+year
labels(i) = a & "<*br*><*font=arialbi.ttf*>" & b
Else
labels(i) = a
End If
data0(i) = nur2G(1, i + s)
Next i
I don't know if it is the best approach but at least it works. The only inconvenience is the labels exceed the chart area when I scrolling. See che chart resulted below:
|
Re: How to insert a second xAxis ? |
Posted by Peter Kwan on May-24-2017 02:46 |
|
Hi Daniel,
In the "Zooming and Scrolling" example, the x-coordinates are passed to ChartDirector as date, and configure ChartDirector to do the formatting. ChartDirector can be configured to add the "month name" only to the first date of a month (using multi-formatted). This method is convenient for a zoomable chart, because the x-axis range can vary widely (from a few days to several years), and ChartDirector can be configured to handle the various case (using conditional formatting).
In your current approach, your code formats the dates into text labels, and passed the formatted labels to ChartDirector. This is most flexible as you can format the label in any way you like. However, the formatted labels are text strings, and ChartDirector would not know the labels represent dates or which parts of the label are the day and month. So for this method, your code would need to determine how to add the month part to the labels.
For your case, I am not sure if the style in the attached image is acceptable to you. In this style, the month part can be added to the first date label in a month. In the image, the month is added to the same line as the day of month, but you can also add it to a separate line. You can also add the year to the same line as the month or to a third line.
To avoid the label overflowing the right border, you may consider to just use a shorter month name. This is how all our sample code avoids this issue.
The code to do the above is like:
For i = 0 To N
d = nur2G(0, i + s)
If i = 0 Then
needMonth = Day(d) < 20
Else
needMonth = Month(d) <> Month(nur2G(0, i + s - 1))
End If
a = Format$(d, "dd")
If needMonth Then
a = a & "<*br*><*font=arialbi.ttf*>" & Format$(d, "mmm") & "<*br*>" & Format$(d, "yyyy")
End If
labels(i) = a
data0(i) = nur2G(1, i + s)
Next i
You can also add the month label at the starting position of the month (note that this is different to the "first date label" of the month, as the "first date label" in your code can be the 2nd day of a month). The easiest method is to add an extra x-axis just below the original x-axis. Instead of adding a label every 2 days, you can add labels only at the start of each month.
Hope this can help.
Regards
Peter Kwan
|
|