} else { $amount = bcadd($amount, $val['final_amount'], 2); $number += 1; } unset($val); } } $key = empty($trend) ? 'day' : $trend; $data['labels'][] = date($format[$key], $v + 28800); $data['amount'][] = $amount; $data['number'][] = $number; unset($amount, $number); } if (is_array($data['amount'])) { $data['amount'] = build_data($data['amount'], $lang[$key] . '销量', $saler); $data['number'] = build_data($data['number'], $lang[$key] . '订单量', $saler); } // 计算纵坐标标尺 $amount = calc_scale($data['amount']); $number = calc_scale($data['number']); $zoom = pow(10, strpos($amount['max'], '.') - strlen(strval($number['max']))); $data['start_scale'] = 0; $offset = round(max($amount['max'] / $zoom, $number['max']), 0); $data['end_scale'] = $offset + ceil($offset / 10); if (isset($data['amount']['value'])) { foreach ($data['amount']['value'] as &$val) { $val = round($val / $zoom, 2); } } else { foreach ($data['amount'] as $key => $val) { foreach ($val as $k => $v) {
require_once 'phplot.php'; # Make a data array for the given X and Y ranges: function build_data($x1, $dx, $nx, $y1, $y2) { $dy = ($y2 - $y1) / ($nx - 1); $data = array(); while ($nx-- > 0) { $data[] = array('', $x1, $y1); $x1 += $dx; $y1 += $dy; } return $data; } // Common setup: $plot = new PHPlot(460, 600); $plot->SetTitle("Multiple Plots, Sticky Settings\n" . "Reset data range and not tick step between plots"); $plot->SetDataType('data-data'); $plot->SetPlotType('linepoints'); $plot->SetPrintImage(False); // Plot #1: $plot->SetPlotAreaPixels(40, 60, NULL, 300); $plot->SetDataValues(build_data(0, 1, 4, 5, 2)); $plot->SetPlotAreaWorld(); $plot->DrawGraph(); // Plot #2: $plot->SetPlotAreaPixels(40, 330, NULL, 570); $plot->SetDataValues(build_data(0, 10, 4, 0, 400)); $plot->SetPlotAreaWorld(); $plot->DrawGraph(); // Finish: $plot->PrintImage();