Yii Framework Forum: Incorrect chart displayed using chart js - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Incorrect chart displayed using chart js

#1 User is offline   Questions 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 15-October 16

Posted 07 November 2017 - 11:30 AM

I am using XAMPP web server.

I have created folder chartexample in htdocs.

Now I want to display database data using chart js.

So I created data.php and bargraph.html files into chartexample folder. Similarly I created app.js file in js folder in chartexample folder.

But when I run this code nothing is display on chart. Below are my code :

I have attached 2 files:

1. data.php

2. bargraph.html



And the content of app.js is as follows:



$(document).ready(function(){

$.ajax({

url: "http://localhost/chartexample/data.php",

method: "GET",

dataType: "json",

success: function(data) {

console.log(data);

var emp = [];

var groups = [];



for(var i in data) {

emp.push(" " + data[i].FirstName);

groups.push(data[i].TotalGroups);

}



var chartdata = {

labels: emp,

datasets : [

{

label: 'SHG Groups',

backgroundColor: 'rgba(200, 200, 200, 0.75)',

borderColor: 'rgba(200, 200, 200, 0.75)',

hoverBackgroundColor: 'rgba(200, 200, 200, 1)',

hoverBorderColor: 'rgba(200, 200, 200, 1)',

data: groups

}

]

};



var ctx = $("#mycanvas");



var barGraph = new Chart(ctx, {

type: 'bar',

data: chartdata

});

},

error: function(data) {

console.log(data);

}

});

});



Attached File(s)


0

#2 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 148
  • Joined: 10-October 11
  • Location:Russia

Posted 07 November 2017 - 12:10 PM

http://www.yiiframew...-in-this-forum/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users