Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Ejdamm committed Oct 29, 2017
1 parent ec3ff2c commit ee7b9ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 55 deletions.
22 changes: 0 additions & 22 deletions .gitattributes

This file was deleted.

74 changes: 41 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
Chart.js-PHP
============

A PHP wrapper for [chartjs/Chart.js](https://github.com/chartjs/Chart.js)

When using a lot of charts in a project, we need to write a lot of code.

This small PHP wrapper use `data-attributes` to load chart with Chart.js with less code.

This project is an expansion of [HugoHeneault's](https://github.com/HugoHeneault/Chart.js-PHP) repository

## Charts implemented
* Line
* Bar
* Radar
* Polar Area
* Pie & Doughnut


## How to use
Include Chart.js and chart.js-php.js before the end of your body (change src according to your project)
Include Chart.js and driver.js before the end of your body (change src according to your project)
```html
<html>
<body>
<!-- Your awesome project comes here -->

<!-- And here are Chart.js and Chart.js-PHP -->
<script src="js/Chart.js"></script>
<script src="js/chart.js-php.js"></script>
<script src="Chart.js"></script>
<script src="driver.js"></script>
</body>
</html>
```

Load ChartJS-PHP classes or use an autoloader
Load ChartJS-PHP class
```php
require 'class/ChartJS.php';
require 'class/ChartJS_Line.php';
require 'ChartJS.php';
```

Then, create your charts using PHP.
Then, create your charts using PHP.
```php
$Line = new ChartJS_Line('example', 500, 500);
$Line->addLine(array(1, 2, 3, 4));
$Line->addLabels(array('A label', 'Another', 'Another one', 'The last one'));
$labels = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday');
$options = array();
$attributes = array('id' => 'example', 'width' => 500, 'height' => 500);
$Line = new ChartJS('line', $labels, $options, $attributes);

$dataset = array(
'data' => array(8, 7, 8, 9, 6),
'backgroundColor' => '#f2b21a',
'borderColor' => '#e5801d',
'label' => 'Legend'
);
$Line->addDataset($dataset);

// Echo your line
echo $Line;
Expand All @@ -59,12 +53,20 @@ Finally, load these charts with a small piece of javascript when your document i
## Full example
```php
<?php
require 'class/ChartJS.php';
require 'class/ChartJS_Line.php';
require 'ChartJS.php';

$Line = new ChartJS_Line('example', 500, 500);
$Line->addLine(array(1, 2, 3, 4));
$Line->addLabels(array('A label', 'Another', 'Another one', 'The last one'));
$labels = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday');
$options = array('responsive' => false);
$attributes = array('id' => 'example', 'width' => 500, 'height' => 500);
$Line = new ChartJS('line', $labels, $options, $attributes);

$dataset = array(
'data' => array(8, 7, 8, 9, 6),
'backgroundColor' => '#f2b21a',
'borderColor' => '#e5801d',
'label' => 'Legend'
);
$Line->addDataset($datasets);

?><!DOCTYPE html>
<html>
Expand All @@ -74,9 +76,9 @@ $Line->addLabels(array('A label', 'Another', 'Another one', 'The last one'));
<body>
<?php
echo $Line;
?>
?>
<script src="Chart.js"></script>
<script src="chart.js-php.js"></script>
<script src="driver.js"></script>
<script>
(function() {
loadChartJsPhp();
Expand All @@ -86,5 +88,11 @@ $Line->addLabels(array('A label', 'Another', 'Another one', 'The last one'));
</html>
```

## Documentation
Full documentation is available at [Chart.js](http://www.chartjs.org/docs/latest/charts/) website. There you can find what type of charts and associated properties are available.

## Time axis
If you are going to use time axis you need either to include Moment.js or Chart.bundle.js instead of Chart.js to your project. Chart.bundle.js consists of both Chart.js and Moment.js (which is needed for time axis).

## Contributing
Do not hesitate to edit or improve my code with bugfix and new functionnalities !
Do not hesitate to edit or improve my code with bugfix and new functionnalities!

0 comments on commit ee7b9ab

Please sign in to comment.