Chart in PHP

Good Morning.

I need to create a PHP page where the result of a select is brought in the form of html chart.

The select is simple, it will be two columns:

Column 1 - Analyst
Column 2 - Number

The Select returns the number of incidents assigned to each analyst.

I would like the help of experts for the development of this code.

Attached an example that I generate in excel

The select will run on SQL Server.

Thank you.
Capturar.PNG
Support_38Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott FellDeveloper & EE ModeratorCommented:
I'm pretty sure you can do this in pure php.  However, charting will be much faster if you can do it on the client side of things.  There are a number of libraries for this.

http://www.chartjs.org/
http://www.highcharts.com/
https://d3js.org/
http://morrisjs.github.io/morris.js/
.... and many more

You will see for both samples, you just need to output json data
http://www.chartjs.org/docs/#bar-chart-introduction
var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.5)",
            strokeColor: "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.5)",
            strokeColor: "rgba(151,187,205,0.8)",
            highlightFill: "rgba(151,187,205,0.75)",
            highlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
};

Open in new window

Ray PaseurCommented:
You might want to consider JpGraph.

If you need some hands-on help, you might want to consider using E-E Gigs, where you can pay an expert to help you build the app.  Here's how to do the basics, using simulated data that might be found in the query results set.
http://iconoun.com/demo/temp_alex.php
<?php // demo/temp_alex.php
/**
 * http://www.experts-exchange.com/questions/28932886/Chart-in-PHP.html
 *
 * http://jpgraph.net/
 */
error_reporting(E_ALL);
ob_start();

// A SIMULATED RESULTS SET FROM A SQL QUERY
$results_set = array
( [ 'user' =>  'user1', 'qtde' => 60 ]
, [ 'user' =>  'user2', 'qtde' => 33 ]
, [ 'user' =>  'user3', 'qtde' => 26 ]
, [ 'user' =>  'user4', 'qtde' => 23 ]
, [ 'user' =>  'user5', 'qtde' => 21 ]
, [ 'user' =>  'user6', 'qtde' => 15 ]
, [ 'user' =>  'user7', 'qtde' => 11 ]

, [ 'user' => 'user14', 'qtde' =>  3 ]
, [ 'user' => 'user27', 'qtde' =>  1 ]

)
;

// COLLECT THE DATA SET FROM THE SQL RESULTS SET
$datas = $users = [];
foreach ($results_set as $row)
{
    $users[] = $row['user'];
    $datas[] = $row['qtde'];
}


// THE GRAPH TOOL
require_once ('jpgraph-3.5.0b1/src/jpgraph.php');
require_once ('jpgraph-3.5.0b1/src/jpgraph_bar.php');

// THE GRAPH SIZE AND STRUCTURE
$graph = new Graph(400,400);
$graph->SetScale("textlin");
$graph->SetTheme(new UniversalTheme);

$graph->yaxis->SetTickPositions(array(0,20,40,60,80,100), array(10,30,50,70,90));
$graph->SetBox(false);

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels($users);
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

// ADD THE DATA TO THE GRAPH
$barplot = new BarPlot($datas);
$graph->Add($barplot);
$barplot->SetColor("white");
$barplot->SetFillColor("red");
$graph->title->Set("Example Bar Plot");

// DISPLAY THE GRAPH
$graph->Stroke();

Open in new window

Support_38Author Commented:
Good Morning,

Has helped a lot, I'll do here, then I say if it worked.

Thank you.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Slick812Commented:
greetings  Alex, , The way that a PHP and javascript CHART is made depends on the Chart you need to build. I looked at the image in your   Capturar.PNG  that you have here, and at the very Top of that Image , you have columns labeled A to M , can you tell us what code you used to make that chart, and what the columns labeled A to M, are used for?
Also if you tell us about what the things to need to chart, like "Prices", "Car Sales", "Voting Results" or "Sports Scores", then we can tell you what we might use to chart that type of value in a vertical Chart.

The more you can say about your chart, the more we can tell you about the ways to do it.
Support_38Author Commented:
Hello,

It is a portal where you will be told the number of alarms assigned to each analyst.

The query is quite simple.

The select is attached.

Thank you.
select.txt
Ray PaseurCommented:
Hi, Alex.  That will work fine with JpGraph.  Try the code here:
http://www.experts-exchange.com/questions/28932886/Chart-in-PHP.html#a41506141

About the only thing that must change would be to insert the query and fetch the results set.  You would do this in place of the SIMULATED RESULTS SET that is used in the demonstration script.  The other settings can be adjusted to suit your exact display needs.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Support_38Author Commented:
Thank you.

It helped.
Support_38Author Commented:
Thank you for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.