|
X-& Y-Axis |
Posted by Chris Johnson on Jun-14-2007 22:22 |
|
Hello, two questions from a beginner...
First, I am feeding one year's worth of daily data into a line chart. The graph is defaulting to print each date accross the X-Axis label which results in a solid black line (from the overlapping). How can I change the settings so that the X-Axis labels are only displaying one date every two or three weeks?
Second, the scaling of the Y-axis starts at 0.0 by default. How can I change this to the lowest reading of the data that is loaded into the array to plot this line?
Thanks in advance for any help!
CJ |
Re: X-& Y-Axis |
Posted by Rodney Rindels on Jun-15-2007 00:18 |
|
> First, I am feeding one year's worth of daily data into a line chart. The
> graph is defaulting to print each date accross the X-Axis label which
> results in a solid black line (from the overlapping). How can I change the
> settings so that the X-Axis labels are only displaying one date every two or
> three weeks?
In my perl version the following function seems to do the trick.
setLabelStep(majorTickStep [, minorTickStep [, majorTickOffset [, minorTickOffset ]]])
DescriptionShows a regularly spaced subset of the axis labels on the axis.This method is typically used in conjunction with Axis.setLabels or Axis.setLabels2. These two methods define the full set of labels on the axis, one for each data point in a data set. In many cases, there may be too many labels and the axis may become overcrowded with labels. The setLabelStep method will cause the axis to show a regularly spaced subset of labels instead all labels.
HTH,
Rodney |
Re: X-& Y-Axis |
Posted by Peter Kwan on Jun-15-2007 00:55 |
|
Hi Chris,
The setLabelStep method suggested by Rodney are useful to make regularly spaced labels. In VB/VBScript, it is like:
'show one label per 14 labels
Call c.xAxis().setLabelStep(14)
If your x data series are really dates (note: in ASP/VB/VBScript, a date means a variable of type Date, not a text string), you may also use setLabels2 with setMultiFormat2, using StartOfWeekFilter or StartOfMonthFilter. This method works even if you want to put one label per month. (setLabelStep will not work for months, because a month is of variable length). The code is:
Call c.xAxis().setLabels2(myArrayOfDates)
Call c.xAxis().setMultiFormat2(cd.StartOfMonthFilter())
For the y-axis starting from 0, ChartDirector auto-scaling may or may not start the y-axis from 0, depending on your data. If your data range is 99 - 101, probably ChartDirector will not start the y-axis from 0. However, if your data range is 50 - 200, ChartDirector probably will start the y-axis from 0 (instead of from 50). The threshold that controls whether ChartDirector starts the y-axis from 0 or not are the bottom scale margin, and the "zero affinity" parameter. See Axis.setAutoScale for more information.
If you do not want ChartDirector to favour starting the y-axis from 0, you may use setAutoScale to set the "zero affinity" to 0. For example:
'top and bottom scale margin = 5%. no zero affinity
Call c.yAxis().setAutoScale(0.05, 0.05, 0)
Most people would not want the y-axis to start at the lowest data value. Some margin may be desirable, otherwise some points on the line with touch the x-axis. Also, if the lowest data value happens to be like 21.2741, most people may would the y-axis to be rounded to some "nice value" (like 20), rather than start at an "odd value", like 21.2741.
Anyway, if you want the lower point of the y-axis to be exactly the lowest value of your data, you may set the scale margin to 0, and disable axis end point rounding. The code is:
'no margin, no rounding, no zero affinity
Call c.yAxis().setAutoScale(0, 0, 0)
Call c.yAxis().setRounding(False, False)
Hope this can help.
Regards
Peter Kwan |
Re: X-& Y-Axis |
Posted by Peter Kwan on Jun-15-2007 00:59 |
|
Hi Chris,
Sorry. I made a mistake. The setMultiFormat2 code should be:
Call c.xAxis().setLabels2(myArrayOfDates)
Call c.xAxis().setMultiFormat2(cd.StartOfMonthFilter(), "{value|mmm yy}")
Hope this can help.
Regards
Peter Kwan |
Re: X-& Y-Axis |
Posted by Brad on Feb-09-2012 23:26 |
|
Peter Kwan wrote:
Hi Chris,
Sorry. I made a mistake. The setMultiFormat2 code should be:
Call c.xAxis().setLabels2(myArrayOfDates)
Call c.xAxis().setMultiFormat2(cd.StartOfMonthFilter(), "{value|mmm yy}")
Hope this can help.
Regards
Peter Kwan
Peter,
Does this work for PHP as well? I tried
$c->xAxis->setLabels2($labels);
$c->xAxis->setMultiFormat2(StartOfMonthFilter(), "{value|mmm yy}");
but no labels show up. I'm trying to do the same thing as Chris, but in PHP.
Thanks, Brad |
Re: X-& Y-Axis |
Posted by Peter Kwan on Feb-10-2012 02:19 |
|
Hi Brad,
Yes. The code works with PHP (as well as all editions of ChartDirector).
Note that for the code to work, $labels must be an array of date/time. However, there is no such thing called date/time in the PHP language (unlike VB, .NET, Java, etc, that does have a special data type for date/time). So in ChartDirector for PHP, the date/time must be represented using a ChartDirector specific format, which is a number representing the clock seconds elapsed since Jan 1, 0001 00:00:00. The number can be generated using the ChartDirector method chartTime or chartTime2.
Note that using date/time representing in English or Chinese or any human language format would not work.
Hope this can help.
Regards
Peter Kwan |
Re: X-& Y-Axis |
Posted by Brad on Feb-23-2012 23:58 |
|
Peter Kwan wrote:
Hi Brad,
Yes. The code works with PHP (as well as all editions of ChartDirector).
Note that for the code to work, $labels must be an array of date/time. However, there is no such thing called date/time in the PHP language (unlike VB, .NET, Java, etc, that does have a special data type for date/time). So in ChartDirector for PHP, the date/time must be represented using a ChartDirector specific format, which is a number representing the clock seconds elapsed since Jan 1, 0001 00:00:00. The number can be generated using the ChartDirector method chartTime or chartTime2.
Note that using date/time representing in English or Chinese or any human language format would not work.
Hope this can help.
Regards
Peter Kwan
Thanks Peter. I'm probably doing something dumb, but I cannot get the setMultiFormat function to work correctly. Any help would be greatly appreciated. I'm interested in displaying only the first day of the months or first day of weeks, depending on what timeframe is selected. I dont want to display any other date other than the first or the respective timeframe.
In the attached code, I'm strictly working on the first day of the month scenario. I'm just assuming that once I get this working, I can change my StartOfMonthFilter() to StartOfWeekFilter().
Thanks again for any help you can provide,
Brad
|
Re: X-& Y-Axis |
Posted by Peter Kwan on Feb-24-2012 02:43 |
|
Hi Brad,
Instead of setLabels, may be you can try setLabels2.
If setLabels is used, ChartDirector will treat the $labels to be text strings, and will not attempt to interpret them. The labels become like "names" without any meaning to ChartDirector, and ChartDirector will just display them as is.
If setLabels2 is used, ChartDirector will assume the $labels to be numeric or date/time, and so filtering will work.
Hope this can help.
Regards
Peter Kwan |
Re: X-& Y-Axis |
Posted by Brad on Feb-24-2012 22:37 |
|
Worked like a charm. Thanks a lot Peter. I must have overlooked the setLabels2 distinction in any of the examples/forums I was searching though. Glad it was an easy fix.
Thanks again,
Brad |
|