-1

I am working on project based on a website with NodeJs and AngularJs. I am a beginner and somehow have written the code based on the architecture of how these two interact with each other. I have also incorporated the code for plotting the graph with static values using FusionChart library in a file called fusionchart.js.

However, I am struggling to replace the static dataset with the dynamic one which is getting read from a server in a filename dynamicdata.js.

I cannot share the code due to the "code share clause" but Can someone help me in figuring out what should be the steps to make sure the dynamic data in dynamicdata.js is visible in the fusionchart.js?

2
  • 2
    You need to provide the actual code for your project so that people can help you debug it. Commented Oct 17, 2017 at 0:07
  • so is dynamicdata.js on the server? Commented Oct 17, 2017 at 17:26

2 Answers 2

0

It is pretty difficult to help you without posting you code. If I understand correctly, you have some set of functions which produce data on the server, and you want to pass this to the client.

In order to do this, you need to use some sort of client/server communication mechanism. Perhaps the easiest is ajax- your server would respond to HTTP get requests, and send back the data in JSON format. I would read this guide, as it should be a good foundation for writing your app.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, the thing is there is global variable in dynamicdata.js which is a json object and i want to use this variable in the angular controller. For example: In dynamicdata.js: var a; some function(){ //reads data from server and saves it in a; return a; } Now in the fusionchart.js, there is an angular controller: var app = angular.module('app',[]); app.controller('myController,' function($scope){ // i want that var a in here });
@emilybrown take a look at that link
0

You pass the complete JSON/XML chart data as a static string to the dataSource attribute. Alternatively, you can also save the chart data in a .json or .xml file and then pass the relative URL of this file as value to the dataSource attribute.

The only difference between the two methods is the value that is passed to the dataFormat attribute. For the first method, the dataFormat attribute takes json or xml as value, depending on the chart data. For the second method, the value is jsonurl or xmlurl.

//  Require AngularJS 
var angular = require('angular');

// Require FusionCharts 
var FusionCharts = require('fusioncharts');

// Require angularjs-fusioncharts 
require('angularjs-fusioncharts');

// Require Chart modules 
var Charts = require('fusioncharts/fusioncharts.charts');

// Require Fusion theme
var FusionTheme = require('fusioncharts/themes/fusioncharts.theme.fusion');

// Initialize Charts with FusionCharts instance
Charts(FusionCharts);

// Initialize FusionTheme with FusionCharts instance
FusionTheme(FusionCharts);

var myApp = angular.module("myApp", ["ng-fusioncharts"]);

myApp.controller('MyController', ['$scope', function($scope) {
    $scope.dataSource = { datasource }
}

Document reference - https://www.fusioncharts.com/dev/getting-started/angular/angularjs/setting-data-source-using-url-in-angularjs

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.