Abstract
This section contains information about creating labels which identify data values on the plot. There are two types of labels for X values: data labels and tick labels. There are also tick labels for Y values, and data labels for Y values which only work with bar charts. None of this applies to pie charts, which have no tick labels and internally-generated data value labels.
Tick labels are calculated from the X or Y values of the data. By default, PHPlot will figure out what to use for X and Y tick labels, but the results may not be what you want. You can change the calculated tick labels by using several PHPlot functions. You can use SetXTickIncrement and SetYTickIncrement to set the spacing between tick marks (in World Coordinates), or you can use SetNumXTicks and SetNumYTicks to set the number of tick marks. These don't affect the value of the first tick mark, only the interval. To set the value for the first tick mark, you define the World Coordinate mapping with SetPlotAreaWorld. For example:
$plot->SetPlotAreaWorld(-10, NULL, 10, NULL); $plot->SetXTickIncrement(1);
This results in the X tick labels going from -10 to 10, with a tick mark every 1 data unit.
Note that even with data type 'data-data', where explicit X values for the data are supplied, the X tick labels are still calculated automatically (unless modified by the functions named above). That is, your supplied X values in the data array are not used for tick labels.
Both X tick labels and Y tick labels are plotted by default, and can be disabled or repositioned with SetXTickLabelPos and SetYTickLabelPos.
Data labels apply to X values for all plot types. X data labels are supplied in your data array for each data point. For example, with data type text-data :
$data = array( array('Peaches',100), array('Apples', 140), array('Pears', 90));
The three points have data labels 'Peaches', 'Apples', and 'Pears'. These data labels will be drawn at the bottom of the plot (by default) below the corresponding X values. X data labels are drawn by default. You can disable or reposition the labels with SetXDataLabelPos.
Since by default both X data labels and X tick labels are enabled, you need to turn one off or you will get overlapped, double labels. (Unless the label strings in your data array are empty.) If you enable or position X tick labels, then PHPlot will automatically turn off X data labels. If you enable or position X data labels, then PHPlot will automatically turn off X tick labels. But if you do neither, you get both tick and data labels.
There is one type of Y data label for bar charts. Use SetYDataLabelPos to enable Y data labels, which indicate the Y value right above each bar. Example 5.19, “Bar Chart with Data Labels” shows a bar chart with Y data labels.
Both tick and data labels are subject to format controls. There are three choices in formatting. By default, the label value itself is simply displayed. Use SetXLabelType and SetYLabelType to select one of the other two format types: 'time' or 'data', as described in the following paragraphs.
Label type 'data' expects the tick or data label values to be numbers, and formats the values as floating point numbers with a comma between every group of thousands and a fixed number of decimal places. Use SetPrecisionX and SetPrecisionY to select the number of decimal places. By default, the precision is 1, meaning there will be one decimal position after the decimal point.
Label type 'time' expects the tick or data label values to be a PHP time
values (number of seconds since a fixed base data, the Unix Epoch).
PHPlot will format the labels according to the format string you provide
with SetXTimeFormat or SetYTimeFormat.
Refer to the PHP documentation for strftime()
for
details on the format string, but here are some examples for 31 December
2004 at 1:23:45 pm:
Format String: | Result: |
---|---|
%Y-%m-%d | 2004-12-31 |
%b %Y | Dec 2004 |
%b %d, %Y | Dec 31, 2004 |
%d %b | 31 Dec |
%H:%M:%S | 13:23:45 |
If you select 'time' formatting, but don't set a time format string, PHPlot-5.0rc3 and higher will format the values as hours, minutes, and seconds as shown in the last row of the table above. (The default format was undefined before version 5.0rc3.)
Also note that there are limits to the range of this type of formatting that can make it unusable for historical data. On some platforms, dates before 1970-01-01 can not be formatted.
Starting with PHPlot-5.0.4, empty string values for data labels are ignored for 'time' and 'data' formatting. Earlier versions would format the labels as 0 (for 'data') or cause an error (for 'time').
While date/time formatting can be useful, for X values it may be easier to just format the label values in your PHP code and put the result into the label positions in the data array. If you need date/time formatting for Y values (and it is hard to imagine where that would be useful), you have no option but to use the 'time' format labels for tick values.