mirror of
https://github.com/seigler/neat-charts
synced 2025-07-27 01:16:09 +00:00
added options for sparklines
This commit is contained in:
parent
f43540f785
commit
5d73afddd0
3 changed files with 91 additions and 63 deletions
46
demo.php
46
demo.php
|
@ -1,5 +1,20 @@
|
|||
<?php
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
function randomData($count = 96) {
|
||||
$randomData = [];
|
||||
$offset = 100 * (rand()/getRandMax())**4;
|
||||
$scale = 100 * (rand()/getRandMax())**2;
|
||||
$volatility = 0.5 * (rand()/getRandMax())**3;
|
||||
for ($n = 0, $current = $offset + 0.5 * $scale; $n < $count; $n++) {
|
||||
$current -= $offset;
|
||||
$current *= 1 + $volatility * (rand()/getRandMax() - 0.5);
|
||||
$current += $offset;
|
||||
$randomData[$n] = $current;
|
||||
}
|
||||
return $randomData;
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
|
@ -27,18 +42,7 @@ require_once 'vendor/autoload.php';
|
|||
<h2>SVG chart in <code>svg</code> tag</h2>
|
||||
<figure>
|
||||
<?php
|
||||
$chartData = [];
|
||||
$offset = 100 * (rand()/getRandMax())**4;
|
||||
$scale = 100 * (rand()/getRandMax())**2;
|
||||
$volatility = 0.5 * (rand()/getRandMax())**3;
|
||||
for ($n = 0, $current = $offset + 0.5 * $scale; $n < 96; $n++) {
|
||||
$current -= $offset;
|
||||
$current *= 1 + $volatility * (rand()/getRandMax() - 0.5);
|
||||
$current += $offset;
|
||||
$chartData[$n] = $current;
|
||||
}
|
||||
|
||||
$chart = new NeatCharts\LineChart($chartData, [
|
||||
$chart = new NeatCharts\LineChart(randomData(), [
|
||||
'width'=>800,
|
||||
'height'=>250,
|
||||
'lineColor'=>'#F00',
|
||||
|
@ -47,6 +51,24 @@ $chart = new NeatCharts\LineChart($chartData, [
|
|||
'fontSize'=>14
|
||||
]);
|
||||
echo $chart->render();
|
||||
?>
|
||||
<figcaption>Random generated data, loaded right in the page</figcaption>
|
||||
</figure>
|
||||
</section>
|
||||
<section>
|
||||
<h2>SVG sparkline in <code>svg</code> tag</h2>
|
||||
<figure>
|
||||
<?php
|
||||
$chart = new NeatCharts\LineChart(randomData(48), [
|
||||
'width'=>100,
|
||||
'height'=>20,
|
||||
'lineColor'=>'#000',
|
||||
'smoothed'=>false,
|
||||
'fontSize'=>2,
|
||||
'yAxisEnabled'=>false,
|
||||
'xAxisEnabled'=>false
|
||||
]);
|
||||
echo $chart->render();
|
||||
?>
|
||||
<figcaption>Random generated data, loaded right in the page</figcaption>
|
||||
</figure>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue