// Fake some suitable random data $now = time(); $datax = array($now); for ($i = 0; $i < 360; $i += 10) { $datax[] = $now + $i; } $n = count($datax); $datay = array(); for ($i = 0; $i < $n; ++$i) { $datay[] = rand(30, 150); } // Setup the basic graph $graph = new Graph(324, 250); $graph->SetMargin(40, 40, 30, 70); $graph->title->Set('Date: ' . date('Y-m-d', $now)); $graph->SetAlphaBlending(); // Setup a manual x-scale (We leave the sentinels for the // Y-axis at 0 which will then autoscale the Y-axis.) // We could also use autoscaling for the x-axis but then it // probably will start a little bit earlier than the first value // to make the first value an even number as it sees the timestamp // as an normal integer value. $graph->SetScale("intlin", 0, 200, $now, $datax[$n - 1]); // Setup the x-axis with a format callback to convert the timestamp // to a user readable time $graph->xaxis->SetLabelFormatCallback('TimeCallback'); $graph->xaxis->SetLabelAngle(90); // Create the line $p1 = new LinePlot($datay, $datax); $p1->SetColor("blue"); // Set the fill color partly transparent
function ShowGraphImg() { $this->Init(); $_GET['offset'] = 0; $_GET['limit'] = -1; $data = $this->GetData(); $y = 8; if ($this->events) { foreach ($this->events as $key => $val) { $temp = 'ydata' . $y; ${$temp} = array(); $y++; } } foreach ($data['rows'] as $i => $row) { $xdata[] = $row; $ydata1[] = isset($data['visit'][$i]) ? (int) $data['visit'][$i] : 0; $ydata2[] = isset($data['no_reklama'][$i]) ? (int) $data['no_reklama'][$i] : 0; $ydata3[] = isset($data['clients'][$i]) ? (int) $data['clients'][$i] : 0; $ydata4[] = isset($data['uvisit'][$i]) ? (int) $data['uvisit'][$i] : 0; $ydata5[] = isset($data['hosts'][$i]) ? (int) $data['hosts'][$i] : 0; $ydata6[] = isset($data['loads'][$i]) ? (int) $data['loads'][$i] : 0; $ydata7[] = isset($data['for_page'][$i]) ? (int) $data['for_page'][$i] : 0; $y = 8; if ($this->events) { foreach ($this->events as $key => $val) { $temp = 'ydata' . $y; array_push(${$temp}, isset($data['event_' . $key][$i]) ? (int) $data['event_' . $key][$i] : 0); $y++; } } } $graph_width = $data['count'] * 20; if ($graph_width < $this->graph_width) { $graph_width = $this->graph_width; } include "jpgraph/jpgraph.php"; include "jpgraph/jpgraph_line.php"; // Create the graph and specify the scale for both Y-axis $graph = new Graph($graph_width, $this->graph_height, 'auto'); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->SetAlphaBlending(); // Adjust the margin $graph->img->SetMargin(40, 40, 20, 200); // Setup scale $graph->xaxis->SetFont(FF_VERDANA, FS_NORMAL, 8); $graph->xaxis->SetLabelMargin(10); $graph->xaxis->SetTickLabels($xdata); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetFont(FF_VERDANA, FS_NORMAL, 7); // Titles $graph->title->SetFont(FF_VERDANA, FS_BOLD); $graph->title->Set($this->GetTitle()); // $color = 255; // $dcolor = 255*100; if ($this->show_visit) { // Create linear plot $lineplot1 = new LinePlot($ydata1); // Set the color for the plot $lineplot1->SetColor($this->colors[0]); // $lineplot1->SetColor($this->toColor($color)); $lineplot1->SetWeight(2); // Set the legend for the plot $lineplot1->SetLegend($this->str('visitors')); // Add the plot to the graph $graph->Add($lineplot1); } if ($this->show_no_reklama) { $lineplot2 = new LinePlot($ydata2); $lineplot2->SetColor($this->colors[1]); $lineplot2->SetWeight(2); $lineplot2->SetLegend($this->str('no_reklama')); $graph->Add($lineplot2); } if ($this->show_clients) { $lineplot3 = new LinePlot($ydata3); $lineplot3->SetColor($this->colors[2]); $lineplot3->SetWeight(2); $lineplot3->SetLegend($this->str('clients')); $graph->Add($lineplot3); } if ($this->show_uvisit) { $lineplot4 = new LinePlot($ydata4); $lineplot4->SetColor($this->colors[3]); $lineplot4->SetWeight(2); $lineplot4->SetLegend($this->str('new_visitors')); $graph->Add($lineplot4); } if ($this->show_hosts) { $lineplot5 = new LinePlot($ydata5); $lineplot5->SetColor($this->colors[4]); $lineplot5->SetWeight(2); $lineplot5->SetLegend($this->str('ips')); $graph->Add($lineplot5); } if ($this->show_loads) { $lineplot6 = new LinePlot($ydata6); $lineplot6->SetColor($this->colors[5]); $lineplot6->SetWeight(2); $lineplot6->SetLegend($this->str('pages')); $graph->Add($lineplot6); } if ($this->page_id > 0) { $lineplot7 = new LinePlot($ydata7); $lineplot7->SetColor($this->colors[6]); $lineplot7->SetWeight(2); $lineplot7->SetLegend($this->str('for_page')); $graph->Add($lineplot7); } $y = 8; if ($this->events) { foreach ($this->events as $key => $val) { $temp = 'show_event_' . $key; if ($this->{$temp}) { $temp = 'ydata' . $y; $temp2 = 'lineplot' . $y; ${$temp2} = new LinePlot(${$temp}); if (isset($this->colors[$y - 1])) { ${$temp2}->SetColor($this->colors[$y - 1]); } else { ${$temp2}->SetColor($this->colors[$y - 1 - count($this->colors)]); } ${$temp2}->SetWeight(2); ${$temp2}->SetLegend($val['name']); $graph->Add(${$temp2}); } $y++; } } // Adjust the legend position $graph->legend->Pos(0.2, 0.96, 'center', 'bottom'); $graph->legend->SetFont(FF_VERDANA, FS_NORMAL, 8); // Display the graph $graph->Stroke(); }