antoineaugusti / easyphpcharts
用于 chartjs.org 图表的 PHP 类。
v0.1.1
2014-08-02 15:32 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-20 02:03:21 UTC
README
这是一个简单的 PHP 类,用于 https://chart.js.cn 图表。只需用 5 行 PHP 代码即可绘制出美丽的图表!
文档
您可以在 antoineaugusti.github.io/EasyPHPCharts 找到文档。也可以查看文件 examples/examples.php
。
示例
/* // A basic example of a pie chart */ $pieChart = new Chart('pie', 'examplePie'); $pieChart->set('data', array(2, 10, 16, 30, 42)); $pieChart->set('legend', array('Work', 'Eat', 'Sleep', 'Listen to music', 'Code')); $pieChart->set('displayLegend', true); echo $pieChart->returnFullHTML(); /* // An example of a doughnut chart with legend in percentages */ $doughnutChart = new Chart('doughnut', 'exampleDoughnut'); $doughnutChart->set('data', array(2, 10, 16, 30, 42)); $doughnutChart->set('legend', array('Work', 'Eat', 'Sleep', 'Listen to music', 'Code')); $doughnutChart->set('displayLegend', true); $doughnutChart->set('legendIsPercentage', true); echo $doughnutChart->returnFullHTML(); /* // An example of a bar chart with multiple datasets */ $barChart = new Chart('bar', 'examplebar'); $barChart->set('data', array(array(2, 10, 16, 30, 42), array(42, 30, 16, 10, 2))); $barChart->set('legend', array('01/01', '01/02', '01/03', '01/04', '01/05')); // We don't to use the x-axis for the legend so we specify the name of each dataset $barChart->set('legendData', array('Annie', 'Marc')); $barChart->set('displayLegend', true); echo $barChart->returnFullHTML(); /* // An example of a radar chart */ $radarChart = new Chart('radar', 'exampleradar'); $radarChart->set('data', array(20, 55, 16, 30, 42)); $radarChart->set('legend', array('A', 'B', 'C', 'D', 'E')); echo $radarChart->returnFullHTML(); /* // An example of a polar chart */ $polarChart = new Chart('polar', 'examplepolar'); $polarChart->set('data', array(20, 55, 16, 30, 42)); $polarChart->set('legend', array('A', 'B', 'C', 'D', 'E')); echo $polarChart->returnFullHTML();
CSS
一些 CSS 类将被添加到生成的 HTML 中。一个示例 CSS 文件
.chartContainer { float: left; width: 500px; } .containerChartLegend { float: right; width: 500px; } canvas.chart { margin: 20px auto; display: block; } canvas.chart:after { clear: both; } .colorBlock { display: inline-block; width: 45px; height: 15px; vertical-align: middle; margin-right: 15px; } ul.chartLegend { list-style: none; margin-bottom: 30px; } ul.chartLegend li { margin-bottom: 5px; } .floatRight { float: right; } .clearBoth { clear: both; }