diff --git a/README.md b/README.md index 1351d3c..6c639d1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,27 @@ PHP project to generate cached SVG price charts Extract the files from https://github.com/seigler/Dash-SVG-chart/archive/master.zip where you want to use the chart, or from the command line run `git clone "https://github.com/seigler/Dash-SVG-chart" .` in the folder where you want the charts served from. ## Usage -`` +In your PHP file: + +```php +Header('Content-type: image/svg+xml; charset=utf-8'); +Header('Content-Disposition: inline; filename="Dash-24h-chart-' . date('Y-m-d\THisT') . '.svg"'); +include 'buffer.php'; +include 'SVGChartBuilder.php'; + +/* your code here to generate $chartData */ + +print SVGChartBuilder::renderStockChart($chartData, [ + 'width'=>800, + 'height'=>250, + 'lineColor'=>"#1C75BC", + 'labelColor'=>"#777", + 'smoothed'=>false +]); +``` + +In your HTML: +`` ## Credits diff --git a/SVGChartBuilder.php b/SVGChartBuilder.php index 47a1855..7f3dc5c 100644 --- a/SVGChartBuilder.php +++ b/SVGChartBuilder.php @@ -88,7 +88,7 @@ class SVGChartBuilder { http://vis4.net/blog/posts/doing-the-line-charts-right/ */ $aspectRatio = max(0.25, min(0.75, 1 / $averageAbsSlope)); - $height = floor($aspectRatio * $width); + $height = $height ?? floor($aspectRatio * $width); function labelFormat($float, $places, $minPlaces = 0) { $value = number_format($float, max($minPlaces, $places)); diff --git a/index.php b/index.php index 874357b..296606f 100644 --- a/index.php +++ b/index.php @@ -25,4 +25,10 @@ foreach ($last24h as $item) { $chartData[$item->date] = $item->weightedAverage; } -print SVGChartBuilder::renderStockChart($chartData, 700, "#1C75BC"); +print SVGChartBuilder::renderStockChart($chartData, [ + 'width'=>800, + 'height'=>250, + 'lineColor'=>"#1C75BC", + 'labelColor'=>"#777", + 'smoothed'=>false +]);