Comments (2)
First, it should be noted that angular couldn't $watch the function directly while the function definition is changing. So if you use json-tree for changing the options (means, function definitions) you need to subscribe to 'onFunctionChanged' event from json-tree. And then manually refresh the directive. (This is needed only for changing function definition, the others options are $watched by angular).
Second, you can use functions only for those options that can be represented by the functions correctly in the nvd3 core. Say, 'height' is always a number (or null), but 'x' is always a function, 'color' can be both. The common right function definition is:
function(a,b,c,...){ /* do smth */ }
but it should be matched to the correct core definition. Say,
{
...,
x: function(d){ return d[0]; }, /* or d.x, or else. It relies on your data json */
tooltipContent: function (key, x, y, e, graph) { /* do smth, return html */ },
color: function (d, i) { /* do smth */ },
dispatch: { /* events */
tooltipShow: function (e){ /* event handler */ }
}
}
Sometimes you can see something like:
xScale: function i(n){return o(n)}
It is default function definition for some d3 scale, i.e., d3.scale.linear() - this is definitely a function, but this is not a common definition. So, in directive it is can be used something like:
xScale: function(){ return d3.scale.linear();}()
from angular-nvd3.
Here is the only way I have found so far to use a JSON object WITH FUNCTIONS to set the options in the angular directive. First the piece of the JSON object with the necessary functions:
... ,
"x": {
"args": "d",
"body": "return d[0]"
},
"y": {
"args": "d",
"body": "return d[1]"
},...
And then, inside the directive, I do this:
$scope.options = options;
$scope.options.chart.x = new Function(options.chart.x.args,options.chart.x.body);
$scope.options.chart.y = new Function(options.chart.y.args,options.chart.y.body);
With options
being a JSON object that I fetch from the server.
This all seem like the hard way to go about this. Do you have any alternatives to this?
Thanks!
from angular-nvd3.
Related Issues (20)
- collisions of labels in the donut chart
- Is it possible to show the value of a pie chart slice consistently all the time, and not just by hovering over the pie chart HOT 1
- elementClick triggered only the second time HOT 1
- draw tree grap
- Read data from CSV file and Display Bar Chart
- Ionic Support for sunbrust and heatmap
- Customize legends css
- Background color as gradient in stacked area chart HOT 1
- Margin between Y label and Y axis tick values HOT 1
- How collapse child nodes when click on the parent or sub parent nodes
- Unknown provider: nvd3Provider <- nvd3 <- clientDashBoardPageCtrl
- Tooltips unable to disable while scrolling in responsive
- Log scale doesn't work properly with multiBarChart
- multiBarHorizontalChart reduceYTicks not working
- angular.js:13920 TypeError: Cannot read property 'graphs' of undefined
- Duration doesn't appear to have any affect on pieChart donut
- why zero valued point in sunburst chart got selected?
- NVD3 line chart tooltip stuck at old position on re-scale of chart
- Problem with dispatch events on Firefox.
- How to hide root from sunburst graph ?
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 angular-nvd3.