Grouping same instances of a field in a grouped bar chart - CHART.JS

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Grouping same instances of a field in a grouped bar chart - CHART.JS



I have the following SQL query:


select datetime,name,amount
from users
where datetime in ('20180730 060000','20180731 060000','20180801 060000')
group by datetime, name
order by datetime



I want to group same instances of dates in a grouped bar chart (e.g. if datetime is 20180730 060000 for 3 rows, the chart.js will display a grouped bar according to the names related to datetime).



We are currently storing the SQL values in an JSON array. The Javascript file contains the following:


$(document).ready(function()
$.ajax(
url:***,
method: "GET",
dataType: 'json',
cache: false,
success: function(data)
console.log(data);
var DATETIME= ;
console.log(DATETIME);
var AMOUNT= ;

for(var i in data)
DATETIME.push(" " + data[i].DATETIME);
AMOUNT.push(data[i].AMOUNT);


var chartdata =
labels: DATETIME,
datasets: [
label : '',
backgroundColor: 'rgba(0, 0, 255, 0.3)',
borderColor: 'rgba(200, 200, 200, 0.75)',
hoverBackgroundColor: 'rgba(200, 200, 200, 1)',
hoverBorderColor: 'rgba(200, 200, 200, 1)',
data: AMOUNT
]
;
var ctx = $("#mycanvas");

var barGraph = new Chart(ctx,
type: 'bar',
data: chartdata
);
,
error: function(data)
console.log(data);

);
);



This is the output of the array:


["DATETIME":"20180730 060000","NAME":"JOE","AMOUNT":"5132",
"DATETIME":"20180730 060000","NAME":"ALAN","AMOUNT":"4603",
"DATETIME":"20180730 060000","NAME":"MARK","AMOUNT":"21391",
"DATETIME":"20180731 060000","NAME":"JOE","AMOUNT":"6492",
"DATETIME":"20180731 060000","NAME":"ALAN","AMOUNT":"8014",
"DATETIME":"20180731 060000","NAME":"MARK","AMOUNT":"27829",
"DATETIME":"20180801 060000","NAME":"JOE","AMOUNT":"6821",
"DATETIME":"20180801 060000","NAME":"ALAN","AMOUNT":"6938",
"DATETIME":"20180801 060000","NAME":"MARK","AMOUNT":"11961"]



Sample chart





Add some sample table data and the expected result - all as formatted text, not images.
– jarlh
Aug 10 at 9:53





Which dbms are you using?
– jarlh
Aug 10 at 9:53





Hey, not as a comment. Edit the question instead.
– jarlh
Aug 10 at 10:01





Sorry. I'm new at this :) just edited the question.
– user3665022
Aug 10 at 10:08





And what do you want?
– jarlh
Aug 10 at 10:12









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered