enhanced README, fixed Dash chart to match new options

This commit is contained in:
Joshua Seigler 2016-06-28 00:14:21 -04:00
parent 1ed50094fd
commit 29a36eb63f
3 changed files with 29 additions and 3 deletions

View file

@ -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. 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 ## Usage
`<img src="path to the folder where you cloned this project">` 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:
`<img src="path to the PHP file">`
## Credits ## Credits

View file

@ -88,7 +88,7 @@ class SVGChartBuilder {
http://vis4.net/blog/posts/doing-the-line-charts-right/ http://vis4.net/blog/posts/doing-the-line-charts-right/
*/ */
$aspectRatio = max(0.25, min(0.75, 1 / $averageAbsSlope)); $aspectRatio = max(0.25, min(0.75, 1 / $averageAbsSlope));
$height = floor($aspectRatio * $width); $height = $height ?? floor($aspectRatio * $width);
function labelFormat($float, $places, $minPlaces = 0) { function labelFormat($float, $places, $minPlaces = 0) {
$value = number_format($float, max($minPlaces, $places)); $value = number_format($float, max($minPlaces, $places));

View file

@ -25,4 +25,10 @@ foreach ($last24h as $item) {
$chartData[$item->date] = $item->weightedAverage; $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
]);