// Maintian an instance of the chart and
var chart;
// Maintain an Instance of the SVG selection with its data
var chartData;
nv.addGraph(function () {
chart = nv.models.lineChart().margin({
top: 5,
right: 10,
bottom: 38,
left: 10
}).color(["lightgrey", "rgba(242,94,34,0.58)"])
.useInteractiveGuideline(false)
//.transitionDuration(350)
.showLegend(true).showYAxis(false)
.showXAxis(true).forceY([0.4, 1.6]);
chart.xAxis.tickFormat(d3.format('d')).axisLabel("Rounds");
chart.yAxis.tickFormat(d3.format('0.1f'));
var data = economyData();
// Assign the SVG selction
chartData = d3.select('#economyChart svg').datum(data);
chartData.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
function update() {
var data = economyData();
console.log('Test', data);
//d3.select("body").selectAll('#economyChart svg').datum(data).transition().duration(500);
console.log(d3.select("body").selectAll('#economyChart svg'))
// Update the SVG with the new data and call chart
//chartData.datum(data).transition().duration(500).call(chart);
//nv.utils.windowResize(chart.update);
};
// Update the CHART
d3.select("#update").on("click", update);
// Data Calc
function economyData() {
// Your economyData code
// ....
var numRounds = 10;
// Stability of economy
var stable = 0.2,
unstable = 0.6;
var stability = unstable;
// Type of economy
var boom = 0.02,
flat = 0,
poor = -0.02,
economyTrend = boom;
// Range
var start = 1,
max = start + stability,
min = start - stability;
// Arrays
var baseLine = [],
economy = [];
// Loop
for (var i = 0; i < numRounds + 1; i++) {
baseLine.push({
x: i,
y: 1
});
if (i == 0) {
economyValue = 1;
}...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.