質問

I'm working with Laravel 3. I want to make a reporting page on the website. I have some view table as per below:

+---------+-----------------+-------+
| user_id | username        | total |
+---------+-----------------+-------+
|       1 | user            |    12 |
|       2 | admin           |     3 |
|       3 | user2           |     1 |
|       4 | user3           |     1 |
+---------+-----------------+-------+

I want to show the data in chart view. What is the best way to make it?

役に立ちましたか?

解決

I second phpChart. Used it in the past for an online report task. Very easy to create charts quickly.

Here's the solution to your scenario using phpChart based on their online example -- Axis Labels Rotated Text 2:

<?php 
$line = array(array('user', 12), array('admin', 3), array('user2', 1), array('user3', 1));

$pc = new C_PhpChartX(array($line),'user_chart');
$pc->add_plugins(array('canvasTextRenderer'));
//set series
$pc->add_series(array('renderer'=>'plugin::BarRenderer'));
//set axes
$pc->set_axes(array(
    'xaxis'  => array(
        'renderer'=>'plugin::CategoryAxisRenderer',
        'tickRenderer'=>'plugin::CanvasAxisTickRenderer'),
    'yaxis'  => array(
        'autoscale'=>true,
        'tickRenderer'=>'plugin::CanvasAxisTickRenderer')
));

$pc->draw(800,500);
?>

Result: enter image description here

Change the 6th line to PieRenderer you will get a pie chart.

<?php
$line = array(array('user', 12), array('admin', 3), array('user2', 1), array('user3', 1));

$pc = new C_PhpChartX(array($line),'chart_1');
$pc->add_plugins(array('canvasTextRenderer'));
//set series
$pc->add_series(array('renderer'=>'plugin::PieRenderer'));
//set axes
$pc->set_series_default(array(
    'renderer'=>'plugin::PieRenderer',
    'rendererOptions'=>array('showDataLabels'=>true)));
$pc->set_legend(array('show'=>true,
    'rendererOptions'=> array('numberRows'=> 1),
    'location'=> 's'));

$pc->draw(800,500);
?>

enter image description here

Here's a great intro on Codeproject I found: http://www.codeproject.com/Articles/604542/Creating-Interactive-HTML5-Graphs-in-PHP

他のヒント

Laravel doesn't provides any charting library out of the box. You need to find a third party library written in PHP to generate charts from your Laravel app.

Some free library for charting are:

I strongly encourage you to search for php charting library here in StackOverflow to see the opinion from other experienced users.

When choosing a particular library add it to you composer.json file as any other dependency.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top