I am just starting with PHPlot. I have an application that would benefit greatly from adding charts to the reports currently being generated. First, I was looking for MySQL calls based on PDO. I have been able to pull data from my database using the fetchAll(PDO::FETCH_BOTH) command.
But I am trying to build a stacked bar chart with days of the week as the x labels (text) and the sum of incidents (data) as the Y values. I was also trying to stack the values based on an incident code (text).
The examples in the documentation show a separate feed for the column names does this mean I have to do two data queries to get my ranges?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In attempoting to correct my output issue I have been trying to use json_encode() on the dataset resulting from my query. I can echo the data and it appears "correct" visually. But when I attempt to build a chart I get an error "Fatal error: SetDataValues(): Invalid data array (row 0) "
I looked this up in the documentation and wasn;t sure of the underlying cause, but the comments referenced verison5.5 as having a fix. Here is what I have so far:
I am just starting with PHPlot. I have an application that would benefit greatly from adding charts to the reports currently being generated. First, I was looking for MySQL calls based on PDO. I have been able to pull data from my database using the fetchAll(PDO::FETCH_BOTH) command.
But I am trying to build a stacked bar chart with days of the week as the x labels (text) and the sum of incidents (data) as the Y values. I was also trying to stack the values based on an incident code (text).
The examples in the documentation show a separate feed for the column names does this mean I have to do two data queries to get my ranges?
In attempoting to correct my output issue I have been trying to use json_encode() on the dataset resulting from my query. I can echo the data and it appears "correct" visually. But when I attempt to build a chart I get an error "Fatal error: SetDataValues(): Invalid data array (row 0) "
I looked this up in the documentation and wasn;t sure of the underlying cause, but the comments referenced verison5.5 as having a fix. Here is what I have so far:
It is a simple query with DOW as the title, This is the echoed output.
[{"DOW":"Monday","Incidents":"5"},{"DOW":"Tuesday","Incidents":"15"},{"DOW":"Wednesday","Incidents":"9"},{"DOW":"Thursday","Incidents":"9"},{"DOW":"Friday","Incidents":"4"},{"DOW":"Sunday","Incidents":"1"}]
Do I need a separate file for my labels and one for my data array?
Also, what is the layout for the file if I wanted to list the specific incident types as a second label on a stacked bar chart?
the function json_encode just returns a string representation of the data.
Try having $data as an array. Something like
$data = array(
array('Mon', 5),
array('Tue', 15),
array('Wed', 9),
array('Thu', 9),
array('Sat', 4),
array('Sun', 1)
);
See the docs ex-bars1.html for more info and multiple data per day e.g.
$data = array(
array('Mon',5,1),
array('Tue',15,4),
...
);
Last edit: Afan Ottenheimer 2017-05-29