Comments (12)
Yes. It is possible. I won't be able to push an example until later today/tonight.
Until then, try this.
- create a scope variable on the controller for refreshInterval (for polling)
$scope.refershInterval = 5;
- Include $http as a dependency in the controller
function ExampleCtrl($scope, $http){
- Create a function that uses the $http service, and then assigns the results to the $scope.exampleData you are charting
$scope.fetchData = function(){
$http.get('some.url')
.then(function(response){
$scope.exampleData = response;
});
}
- at the end of the controller make a call to fetchData()
- To poll, create a setInterval function at the very end of the controller and call fetchData() within it. Also, note the use of the $scope.$apply function within setInterval.
setInterval(function(){
$scope.$apply(function(){
$scope.fetchData();
})
}, 15000);
from angularjs-nvd3-directives.
Thanks for the quick reply. I had come up with something similar (but I used d3.json() to get the data instead of $http).
The problem is that when you call $scope.fetchData() at the end of the controller nothing happens on the chart. If you use a timer (or interval) it does update the chart just fine.
Seems like some sort of initialization/timing issue.
from angularjs-nvd3-directives.
Ah - I was missing the $scope.refershInterval - it does work with that :-)
from angularjs-nvd3-directives.
Actually - found the real problem. My d3.json function needed to do an apply:
$scope.setData = function (data) {
console.log('set scope')
d3.json('/app/something.json', function(data) {
$scope.$apply(function() {
$scope.exampleData2 = data;
$scope.exampleData = data;
})
});
};
So, what is $scope.refershInterval ? (notice the typo ;-) )
from angularjs-nvd3-directives.
I was using refreshInterval as a polling mechanism. To poll a backend and update the chart. Sorry for the typo. Not enough coffee yet. :)
from angularjs-nvd3-directives.
actually, I think I had some grand visions of setting it dynamically with angular. I intended to pass it to setInterval. Thats what happens when you rush it. :)
from angularjs-nvd3-directives.
Any thought on the following?:
I'd like to have multiple charts on a given page. Each chart will have a different URL for getting the data. Obviously, having the URL hardcoded in the Controller is not optimal. Where would you suggest having the URL passed in? Would I need to instantiate a new instance of the controller for each chart and pass in the URL?
from angularjs-nvd3-directives.
Let me think about the multiple url's.
However, on the multiple charts per page, take a look at the docs for a specific chart (http://cmaurer.github.io/angularjs-nvd3-directives/line.chart.html). There are multiple charts on the page.
The important thing to remember is to make the id unique (d3.js uses that for selection, updating, etc). Also, I am using one controller, but multiple 'invocations' of the same controller.
from angularjs-nvd3-directives.
So on the same page I am using ExampleCtrl multiple times, with different configurations, and different id's (showYAxisExample, and colorExample).
<div ng-controller='ExampleCtrl'>
<nvd3-line-chart data='exampleData' height='300' id='showYAxisExample' showXAxis='true' showYAxis='false' width='550'>
<svg />
</nvd3-line-chart>
</div>
and
<div ng-controller='ExampleCtrl'>
<nvd3-line-chart color='colorFunction()' data='exampleData' height='300' id='colorExample' showXAxis='true' showYAxis='true' width='550'>
<svg /></nvd3-line-chart>
</div>
from angularjs-nvd3-directives.
The solution for multiple urls would depend on the frequency of changes to the urls. If the url's never, or hardly change, then I wouldn't waste a lot of time on it. I would make it as quick and painless as possible to change (json structure in one place?).
If it is going to change a lot, you are going to want to make it really easy to change.
My initial thoughts.
from angularjs-nvd3-directives.
Just added a live data example using weather data from http://api.openweathermap.org
https://github.com/cmaurer/angularjs-nvd3-directives/blob/master/examples/liveData.example.html
from angularjs-nvd3-directives.
Hi,
Actually I have a different problem. Would it be possible with the given solution.
I have a different way of JSON data sets. It looks like this.
Would it be possible to load the two data sets in the same graph.
from angularjs-nvd3-directives.
Related Issues (20)
- how to i18n
- Custom data field names for sunburst..?
- How to achieve horizontal interactive guide line in nvd3 charts
- Need a vertical scroll in multiBarHorizontalChart if no. of bars increases
- How to i get data when iam click on pie chart HOT 2
- Discretebar Chart HOT 1
- Is there a way to save the graph and/or all its data to an xml or xmls ?
- TypeError: nv.dispatch.render_start is not a function HOT 2
- Pie Chart Label Lines with angular-nvd3
- Cannot read property 'disabled' of undefined
- Wrap long axis labels
- TypeError: nv.dispatch.render_start is not a function HOT 1
- Tooltip Not Hide while clicking outside of chart element in IPAD Devices
- Gradient color
- Format of focus chart x axis in "lineWithFocusChart" HOT 2
- Interactive Guideline Not showing on all the data points
- Fixed Labels on xAxis
- When selecting/deselecting legends with multi lines on line chart the lines start showing incorrect colors
- Cannot output data to another component using angular 2 custom event @Output()
- Discrete Bar chart tooltip customize
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularjs-nvd3-directives.