How to create a chart using Laravel?

I work with Laravel 3. I want to make a reporting page on a website. I have a view table as shown below:

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

I want to show the data in a chart. What is the best way to do this?

+4
source share
3 answers

I second phpChart . Used in the past to set an online report. It is very easy to create graphics quickly.

Here is a solution to your scenario using phpChart based on their online example - Axis Labels Rotated Text 2 Designations :

 <?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

Changing the 6th row to PieRenderer gives you 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 introduction to Codeproject I found: http://www.codeproject.com/Articles/604542/Creating-Interactive-HTML5-Graphs-in-PHP

+9
source

Laravel does not provide a graphics library out of the box. You need to find a third-party library written in PHP to create diagrams from your Laravel application.

Some free charting library:

I highly recommend that you search for the php charting library here at StackOverflow to find out the opinions of other experienced users.

When choosing a specific library, add it to the composer.json file like any other dependency.

+5
source

try this library

https://github.com/ConsoleTVs/Charts

You thank me later

0
source

Source: https://habr.com/ru/post/1496939/


All Articles