473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to implement angular js graphs with json data output

Expand|Select|Wrap|Line Numbers
  1. .controller('HomeCtrl', function ($scope, $http, $stateParams, $state) {
  2.  
  3. var samplelineJsonData = [  
  4.                         {
  5.                             "month": "Jan",
  6.                             "noOfUsers": "65"
  7.                         },
  8.                         {
  9.                             "month": "Feb",
  10.                             "noOfUsers": "59"
  11.                         },
  12.                         {
  13.                             "month": "Mar",
  14.                             "noOfUsers": "80"
  15.                         },
  16.                         {
  17.                             "month": "Apr",
  18.                             "noOfUsers": "81"
  19.                         },
  20.                         {
  21.                             "month": "May",
  22.                             "noOfUsers": "56"
  23.                         },
  24.                         {
  25.                             "month": "Jun",
  26.                             "noOfUsers": "55"
  27.                         },
  28.                         {
  29.                             "month": "Jul",
  30.                             "noOfUsers": "40"
  31.                         }
  32.                       ];                          
  33.  
  34. $scope.labels1 = [], $scope.data1 = [];        
  35. for (var i = 0; i < samplelineJsonData.length; i++) {
  36.     $scope.labels1.push(JSON.stringify(samplelineJsonData[i].month));
  37.     $scope.data1.i = parseInt(samplelineJsonData[i].noOfUsers); 
  38.     //$scope.data1.push(parseInt(samplelineJsonData[i].noOfUsers));
  39. }    
  40.  
  41. //alert("data1 : "+$scope.data1); return false;    
  42. $scope.series1 = ['Users'];
  43. $scope.data1 = [[65, 59, 80, 81, 56, 55, 40]]; //lineData; //[[65, 59, 80, 81, 56, 55, 40] ];
  44.  
  45. $scope.labels2 = ["January", "February", "March", "April"];
  46. $scope.series2 = ['Users'];
  47. $scope.data2 = [
  48.                   [81, 56, 55, 40]
  49.                ];    
  50.  
  51. //Iterating thru the json output Start    
  52.  
  53. //Iterating thru the json output End
  54.  
  55. })
  56.  
  57. //The above code doesnt assign values for $scope.data1 as [[65, 59, 80, 81, 56, 55, 40]] from the for () loop traversed .... May I know whats the issue ?
  58.  
  59.  
Oct 28 '15 #1
1 3032
You're trying to use model as an array. You should declare your model as an array first in your init call. It should be

Expand|Select|Wrap|Line Numbers
  1. $scope.labels1 = [], $scope.data1 = [];
Make sure this variable has declared in your controller init call. After that you've iterated the values and push the results in the data then you needn't to iterate again. Try below snippet

Expand|Select|Wrap|Line Numbers
  1. for (var i = 0; i < samplelineJsonData.length; i++)
  2. {    $scope.labels1.push(JSON.stringify(samplelineJsonData[i].month));
  3. $scope.data1.i = parseInt(samplelineJsonData[i].noOfUsers); //Because this is an object
  4. }
Dec 15 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ckpoll2 | last post by:
Hello, Is there any way to create graphs from data within Access without exporting it to Excel? Thanks, Charlie
2
by: nallen05 | last post by:
A friend and I developed a method of querying graphs of data stored in a database with tree-regular expressions (using an XML syntax based on RELAX NG). We are trying to start a startup to...
3
by: xhe | last post by:
I found Jason is a very handy data format for client/server communication. But I just met a problem as follows: I want to read the data replied from server in Jason format, the reply is like...
9
ssnaik84
by: ssnaik84 | last post by:
Hello, I am trying to integrate FlexBox It uses JSON data to populate listbox items. It internally calls a server side page with AJAX, and reads the JSON results from that page. for example,...
7
by: elvehjem | last post by:
Hi, I'm trying to learn JavaScript. I'm missing something that has to do w/ reading stuff from (what I hope is) a JSON data structure. This function: function myFunction(){ ...
2
pradeepjain
by: pradeepjain | last post by:
i have a page post2.php which prints the json array like { page: 1, total: 239, rows: }, {id:'238',cell:}, {id:'237',cell:}, {id:'236',cell:}, {id:'235',cell:},
2
by: heybobo | last post by:
Hi, my aim is to display the content of my json data i receive from my php file. php is sending : PHP---> $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
1
by: gjain123 | last post by:
Hi All, I am passing json data to servlet as below: Ext.Ajax.request({ url: CONTEXTPATH + "/ServletURL", type: 'post', jsonData :{ record: sample, comments: text ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.