Skip to content

Instantly share code, notes, and snippets.

@prudvi
Last active August 19, 2016 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prudvi/e9f46df3cae455ba12e80ee8f5243795 to your computer and use it in GitHub Desktop.
Save prudvi/e9f46df3cae455ba12e80ee8f5243795 to your computer and use it in GitHub Desktop.
nvd3 simple example
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement() {
nv.addGraph(function() {
var chartdata = [{"key":"Apple","values": []}/*, {"key":"Microsoft","values": []}*/]
var arrayInput = [], arrayInput2 = [], max = 600, min = 100;
for (var x = 1990; x <= 2016; x++) {
var a1 = [] , a2 = [];
a1.push(x);a1.push((Math.random() * (max - min) + min).toFixed(0));
a2.push(x);a2.push((Math.random() * (max - min) + min).toFixed(0));
arrayInput.push(a1);
arrayInput2.push(a2);
}
chartdata[0].values = arrayInput;
//chartdata[1].values = arrayInput2;
//nv.models.cumulativeLineChart()
//nv.models.pieChart()
//nv.models.linePlusBarChart()
var chart = nv.models.lineChart()
.x(function(d) { return d[0] })
.y(function(d) { return d[1]/100 })
.color(d3.scale.category10().range())
.useInteractiveGuideline(false)
;
chart.xAxis.axisLabel("In years");
chart.yAxis.axisLabel("Utilization of Products");
d3.select('#chart svg')
.datum(chartdata)
.call(chart);
//TODO: Figure out a good way to do this automatically
nv.utils.windowResize(chart.update);
return chart;
});
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.nvd3 .nv-axis.nv-x path.domain {
stroke-opacity: 1;
}
<body class='with-3d-shadow with-transitions'>
<h1>Welcome to {{appName}}</h1>
{{outlet}}
{{nvd3-component}}
</body>
<div id="chart" style="width: 700px; height: 350px">
<svg></svg>
</div>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0",
"nvd3css": "https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.4/nv.d3.css",
"d3": "https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.2/d3.min.js",
"nvd3":"https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.4/nv.d3.js"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment