SetYDataLabelPos
Prev | PHPlot Function Reference | Next

## SetYDataLabelPos

SetYDataLabelPos — Position and control Y data labels

## Synopsis

    $plot->SetYDataLabelPos($ydlp)

## Description

`SetYDataLabelPos` determines if and where Y data labels are drawn. For horizontal plots, these are Y axis data labels, which display the label strings from your data array. The labels can be drawn at the left side of the plot (left of the Y axis), on the right side, in both positions, or neither. For vertical plots, these are Y data value labels, displaying the value of the data point within the plot area.

## Parameters

`$ydlp`

  A string indicating the desired position for the Y data labels:

  Position | Description
  --- | ---
  plotleft | Data labels left of the plot. This is for horizontal plots.
  plotright | Data labels right of the plot. This is for horizontal plots.
  both | Data labels both left and right of the plot. This is for horizontal plots.
  plotin | Data value labels within the plot area. For bar charts, this displays the value above (or below) each bar. For stacked bar charts, this displays only the bar total labels and not the bar segment labels. For other plot types, see notes below.
  plotstack | Data value labels above (or below) each bar, and below the top of each bar segment. This is valid for vertical stacked bar plots only. It turns on both bar total labels (as with 'plotin') and bar segment labels.
  none | No data labels or data value labels

## Notes

With vertical plots, this function controls the Y data value labels. For examples, see Example 5.19, “Bar Chart with Data Value Labels”, Example 5.20, “Stacked Bars with Y Data Value Labels”, and Example 5.33, “Linepoints Plot with Data Value Labels”. With horizontal plots, this function controls the Y axis data labels. For examples, see Example 5.27, “Horizontal Bar Chart” and Example 5.28, “Horizontal Stacked Bar Chart”, where the labels are enabled by default and displayed to the left of the Y axis.

The default position for Y data labels (for horizontal plots) is left of the plot. However, PHPlot only enables the data labels if SetYDataLabelPos was used to position them, or if SetYTickLabelPos was not used to enable the tick labels and the data labels are not all empty.

The default position for Y data value labels (for vertical plots) is 'none', meaning no labels. For plot types 'bars' and 'stackedbars', Y data value labels are drawn (if enabled) at fixed positions within or above/below the bars. For plot types 'lines', 'points', 'linepoints', and 'squared', Y data labels are drawn (if enabled) above the data points by default. The position can be changed (see Section 4.7.7, “Tuning Labels”), but PHPlot does not attempt to prevent interference between the labels and other plot elements. Y data value labels are not available with other plot types.

For tick labels, see SetYTickLabelPos.

The bar segment labels, if enabled ('plotstack'), are drawn inside the bars and may not be very visible if dark colors are used for the bar fill. Bar segment labels will be omitted for segments which are too narrow.

Y data value labels will be drawn below the bars for negative values. This only applies to vertical bar charts. Stacked bar charts are not allowed to have negative values.

If Y data lines are enabled with SetDrawYDataLabelLines, then SetYDataLabelPos() also determines the direction of the lines which are drawn from the data points.

The Y data label text angle is set with SetYDataLabelAngle. The Y data label text format can be controlled with SetYDataLabelType or SetYLabelType.

Y data value labels do work with error plots (plot types 'lines', 'points', and 'linepoints' and data type data-data-error). The labels will identify the base Y values of the points. However, the default label position above the points will overlap the error bars. To prevent this, change the position angle as explained in Section 4.7.7, “Tuning Labels”). For example:

    // Setup for error plot with data value labels
    $plot->SetDataType('data-data-error');
    $plot->SetYDataLabelPos('plotin');
    $plot->data_value_label_angle = 45; // Position the labels at 45 degrees

## History

Data value labels were first available for error plots in PHPlot-6.0.0.

Through PHPlot-5.2.0, data value labels were only available for bars and stackedbars plot types. Starting with PHPlot-5.3.0, data value labels are also implemented for lines, points, linepoints, and squared plot types.

Horizontal plot types were added in PHPlot-5.1.2 and PHPlot-5.1.3, and the Y Data Labels were extended to include the Y axis data labels for horizontal plots in addition to the data value labels for vertical plots.

The data value label feature for stacked bar graphs was added in PHPlot-5.1.1.

The data value label feature for bar graphs was added to PHPlot-5.0rc3.

Prev | Up | Next
SetYDataLabelAngle | Home | SetYDataLabelType