$plot->SetImageBorderType('plain'); // For presentation in the manual $plot->SetTitle('Hourly Data Example Plot'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotType('lines'); # Make the X tick marks (and therefore X grid lines) 24 hours apart: $plot->SetXTickIncrement(60 * 60 * 24); $plot->SetDrawXGrid(True); # Anchor the X tick marks at midnight. This makes the X grid lines act as # separators between days of the week, regardless of the starting hour. # (Except this messes up around daylight saving time changes.) $plot->SetXTickAnchor($tick_anchor); # We want both X axis data labels and X tick labels displayed. They will # be positioned in a way that prevents them from overwriting. $plot->SetXDataLabelPos('plotdown'); $plot->SetXTickLabelPos('plotdown'); # Increase the left and right margins to leave room for weekday labels. $plot->SetMarginsPixels(50, 50); # Tick labels will be formatted as date/times, showing the date: $plot->SetXLabelType('time', '%Y-%m-%d'); # ... but then we must reset the data label formatting to no formatting. $plot->SetXDataLabelType(''); # Show tick labels (with dates) at 90 degrees, to fit between the data labels. $plot->SetXLabelAngle(90); # ... but then we must reset the data labels to 0 degrees. $plot->SetXDataLabelAngle(0); # Force the Y range to 0:100. $plot->SetPlotAreaWorld(NULL, 0, NULL, 100); # Now draw the graph: $plot->DrawGraph();
<?php # PHPlot Example - Horizontal Stacked Bars require_once 'phplot.php'; $column_names = array('Beef', 'Fish', 'Pork', 'Chicken', 'Butter', 'Cheese', 'Ice Cream'); // | | | | | | | $data = array(array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9), array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.699999999999999), array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4), array('1970', 79.59999999999999, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8), array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8)); $plot = new PHPlot(800, 500); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetTitle("U.S. Annual Per-Capita Consumption\n" . "of Selected Meat and Dairy Products"); $plot->SetLegend($column_names); # Move the legend to the lower right of the plot area: $plot->SetLegendPixels(700, 300); $plot->SetDataValues($data); $plot->SetDataType('text-data-yx'); $plot->SetPlotType('stackedbars'); $plot->SetXTitle('Pounds Consumed Per Capita'); # Show data value labels: $plot->SetXDataLabelPos('plotstack'); # Rotate data value labels to 90 degrees: $plot->SetXDataLabelAngle(90); # Format the data value labels with 1 decimal place: $plot->SetXDataLabelType('data', 1); # Specify a whole number for the X tick interval: $plot->SetXTickIncrement(20); # Disable the Y tick marks: $plot->SetYTickPos('none'); $plot->DrawGraph();
$result .= ",{$col}"; } } return "{$result}[{$passthru}]"; } $plot = new PHPlot(800, 600); $plot->SetDataType($data_type); $plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, $max)); $plot->SetPlotType($plot_type); $plot->SetTitle($title); $plot->SetXTitle('X Axis Title Here'); $plot->SetYTitle('Y Axis Title Here'); # Use the same custom formatting function for both label types: # Vertical plots: X axis data labels, Y data value labels # Horizontal plots: X data value labels, Y axis data labels $plot->SetXDataLabelType('custom', 'fmtdl', 'X'); $plot->SetYDataLabelType('custom', 'fmtdl', 'Y'); # Turn off ticks on independent axis, and turn on data value labels. This # depends on the plot type and data type (horizontal or vertical): $label_pos = $plot_type == 'stackedbars' ? 'plotstack' : 'plotin'; if ($data_type == 'text-data-yx' || $data_type == 'data-data-yx') { // Horizontal plot: configure X data value labels $plot->SetYTickPos('none'); $plot->SetXDataLabelPos($label_pos); $plot->SetPlotAreaWorld(0, 0, NULL, $nx); $plot->SetXTickIncrement(1); } else { // Vertical plot: configure Y data value labels $plot->SetXTickPos('none'); $plot->SetYDataLabelPos($label_pos); $plot->SetPlotAreaWorld(0, 0, $nx, NULL);
$plot->SetDataType('data-data'); $plot->SetYDataLabelPos('plotin'); // Enable both X tick and X data labels, but with data labels above. $plot->SetXDataLabelPos('plotup'); $plot->SetXTickLabelPos('plotdown'); $plot->SetPlotBorderType('full'); // Plot #1: $plot->SetPlotAreaPixels(NULL, 80, NULL, 305); if (isset($fmt[1]['x'])) { $plot->SetXLabelType('printf', $fmt[1]['x']); } if (isset($fmt[1]['y'])) { $plot->SetYLabelType('printf', $fmt[1]['y']); } if (isset($fmt[1]['xd'])) { $plot->SetXDataLabelType('printf', $fmt[1]['xd']); } if (isset($fmt[1]['yd'])) { $plot->SetYDataLabelType('printf', $fmt[1]['yd']); } $plot->DrawGraph(); // Plot #2: $plot->SetPlotAreaPixels(NULL, 345, NULL, 570); if (isset($fmt[2]['x'])) { $plot->SetXLabelType('printf', $fmt[2]['x']); } if (isset($fmt[2]['y'])) { $plot->SetYLabelType('printf', $fmt[2]['y']); } if (isset($fmt[2]['xd'])) { $plot->SetXDataLabelType('printf', $fmt[2]['xd']);
$data = $data1; } elseif ($tp['datasign'] < 0) { $data = $data2; } else { $data = array_merge($data1, $data2); } $p = new PHPlot(800, 800); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetXTitle('This is the X Axis Title'); $p->SetYTitle('This is the Y Axis Title'); $p->SetDataValues($data); $p->SetDataType('text-data-yx'); $p->SetPlotType('bars'); $p->SetXDataLabelPos('plotin'); if (isset($tp['shade'])) { $p->SetShading($tp['shade']); } if ($tp['ttf']) { $p->SetFontTTF('x_label', $phplot_test_ttfdir . $phplot_test_ttfonts['sans'], 10); } if ($tp['yaxis0']) { $p->SetYAxisPosition(0); } if (isset($tp['labelangle'])) { $p->SetXDataLabelAngle($tp['labelangle']); } if ($tp['labelformat']) { $p->SetXDataLabelType('data', 1, '', '%'); } $p->SetYTickPos('none'); $p->DrawGraph();
# Use this TrueType font and make labels bigger: $p->SetDefaultTTFont($phplot_test_ttfdir . $phplot_test_ttfonts['sans']); $p->SetFont('x_label', '', 10); $p->SetFont('y_label', '', 10); # Options: X if (isset($tp['x_angle'])) { $p->SetXLabelAngle($tp['x_angle']); } if (isset($tp['xd_angle'])) { $p->SetXDataLabelAngle($tp['xd_angle']); } if (isset($tp['x_type'])) { $p->SetXLabelType($tp['x_type'], $tp['x_type_arg']); } if (isset($tp['xd_type'])) { $p->SetXDataLabelType($tp['xd_type'], $tp['xd_type_arg']); } if (isset($tp['xt_pos'])) { $p->SetXTickLabelPos($tp['xt_pos']); } if (isset($tp['xd_pos'])) { $p->SetXDataLabelPos($tp['xd_pos']); } # Options: Y if (isset($tp['y_angle'])) { $p->SetYLabelAngle($tp['y_angle']); } if (isset($tp['yd_angle'])) { $p->SetYDataLabelAngle($tp['yd_angle']); } if (isset($tp['y_type'])) {