Comments (10)
Can you post a quick example of what you are trying to accomplish?
from angularjs-nvd3-directives.
I don't understand why you would use d3.json?
from angularjs-nvd3-directives.
We got it working by some modifications in the directives. We are not yet sure if this is the proper way to go. Any suggestions?
<nvd3-stacked-area-chart
data = "exampleData" // we do not want to make use of this.
dataurl="{{widget.query.url}}" // eg. URL of json data file
width="550"
height="260"
showLabels = "true"
xaxistickformat="xDateFormat()"
xaxislabel="{{widget.xAxisLabel}}"
yaxislabel="{{widget.yAxisLabel}}"
><svg></svg>
</nvd3-stacked-area-chart>
In the directives.
scope.$watch('dataurl', function(dataurl){
getData(dataurl, createChart) // AJAX load the data and createChart accordingly
}, (attrs.objectequality === undefined ? false : (attrs.objectequality === "true")));
getData function.
function getData(dataurl, callback){
d3.json(dataurl, function(data){
callback.call(this,data);
})
};
from angularjs-nvd3-directives.
@vikaskonsam, this would not be considered an Angular solution. Look at the liveData.example.html in the examples directory.
Instead of using d3.json, use an Angular service (resource, etc), to get the json data from your endpoint, then assign that data to the $scope variable you are using for your data.
By combining the fetching of data within the directive, you are mixing concerns, which complicates the code.
The following is from the liveData example using Angular's service constructs.
function fetchData(){
openWeatherService.getForecast(5506956, 'imperial')
.success(function(response){
var dta = [{key:"Las Vegas Weather", values:[]}];
dta[0].values = response.list.map(function(d){
return [d.dt, d.main.temp];
});
$scope.exampleData = dta;
});
}
Does this make sense?
Chris
from angularjs-nvd3-directives.
@cmaurer - yes, it make sense putting the data in the scope. We have tried your suggestion and have successfully implemented it. Thank you.
However, we do have a concern with this approach:
We have a dashboard screen with multiple charts. The server will send an initial list with which we will be generating the charts.
Eg.
[ { "id":1, "title":"Some title", "type":"simpleLineChart", "query":{ "url":"url to fetch chart data" } }, { "id":2, "title":"Some title", "type":"stackedAreaChart", "query":{ "url":"url to fetch chart data" } }, { .... } ]
We will have to iterate through this entire list, get the url and fetch the data for the chart and add it to the scope. This may increase the initial load time. The dashboard may not come alive unless all the data is fetched.
With the other approach presented earlier the charts are self sufficient and have the mechanism of fetching the data by itself, making use of the dataurl passed as an attribute. This approach will help in asynchronous loading of the charts.
What are your thoughts on these approaches? Which one would you opt for?
from angularjs-nvd3-directives.
The dashboard may not come alive unless all the data is fetched,
Are you thinking that none of the charts will show up until all of the data for every chart has been returned?
With the other approach presented earlier the charts are self sufficient and have the mechanism of fetching the data by itself
Without knowing more about your application, I will have difficulty providing a concrete answer. However, it is true the other approach will make the charts 'self sufficient'. However, how important is self-sufficiency compared to other aspects of your app.
How well does that approach fit within the goals of Angular.js? Directives are intended to be reusable across a wide variety of uses. The more you add to it for a specific use in one application, the harder it is to reuse. The more you decouple, the more reuse you typically get.
What I would suggest is to take a look at some examples (other than charting), where they are combining a number of directives together. In your iteration example, look at the ng-repeat directive and templates. I saw a good example that helped to solidify some of these concepts for me. I will try to find it and post the link.
from angularjs-nvd3-directives.
Are you still having issues? Did my comment help?
Thanks,
Chris
from angularjs-nvd3-directives.
@cmaurer ,
Sorry for the late reply..
We did some testing at our end of both the approaches and have decided to go with the approach you had suggested earlier (the one where we add the data to the $scope).
Reason - we wanted to have the data in the $scope from which it can be accessed to show in a table format.
Thank you for your suggestions. They did help us a lot.
Vikas
from angularjs-nvd3-directives.
Cool. Glad it worked out.
Chris
from angularjs-nvd3-directives.
Hi,
I would like to know how do you pass json data as url. Can you give me an example. Because instead of sending the data in the code, I want to send it as a json file. Is it possible. I really appreciate your help.
Thanks!
Regards,
Sandeep
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.