javascript - Why does the NVD3.js line plus bar chart example render two charts instead of one? -


i put following test code based on example code provided nvd3 team @ library's official website. reason, see 2 charts drawn on page: 1 has proper labels on 2 y-axes , proper labels on x-axis while second more compressed vertically, not have labels on y-axes , has appears data array indices on x-axis.

the code below assumes latest versions of both d3 , nvd3 although behavior still manifests when using older version of d3 website links to.

thanks in advance , insight problem.

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8"/>     <title>line + bar chart | nvd3.js</title>     <link rel="stylesheet" href="nv.d3.css"/>     <style>         #chart svg {             height: 400px;         }     </style> </head> <body>     <div id="chart">         <svg></svg>     </div>     <script src="d3.js"></script>     <script src="nv.d3.js"></script>     <script>         var data = [             {                 'key': 'foo',                 'bar': true,                 'color': 'skyblue',                 'values': [                     [1431993600000, 31.6882],                     [1432080000000, 76.1706],                     [1432166400000, 76.2297],                     [1432252800000, 75.1944],                     [1432339200000, 75.1536],                     [1432425600000, 74.528],                     [1432512000000, 75.7265],                     [1432598400000, 75.8659],                     [1432684800000, 74.6283],                     [1432771200000, 73.3533]                 ]             },             {                 'key': 'bar',                 'color': 'steelblue',                 'values': [                     [1431993600000, 0.0002997961386257345],                     [1432080000000, 0.0004418193656404055],                     [1432166400000, 0.0003122142681920564],                     [1432252800000, 0.00031651293181407124],                     [1432339200000, 0.0003845457835685849],                     [1432425600000, 0.00031934306569343066],                     [1432512000000, 0.0005163317993040745],                     [1432598400000, 0.00042575122683577205],                     [1432684800000, 0.00025057518394496457],                     [1432771200000, 0.00041715914621428076]                 ]             }         ];         nv.addgraph(function () {             var chart = nv.models.lineplusbarchart()                     .margin({                         top: 30,                         right: 60,                         bottom: 50,                         left: 70                     })                     .x(function (d, i) {                         return i;                     })                     .y(function (d, i) {                         return d[1];                     });              chart.xaxis                     .showmaxmin(true)                     .tickformat(function (d) {                         var dx = data[0].values[d] && data[0].values[d][0] || 0;                         return d3.time.format('%x')(new date(dx));                     });              chart.y1axis                     .tickformat(d3.format(',f'));              chart.y2axis                     .tickformat(function (d) {                         return d3.format('g')(d)                     });              chart.bars.forcey([0, 200]);             chart.lines.forcey([0]);              d3.select('#chart svg')                     .datum(data)                     .transition()                     .duration(0)                     .call(chart);              nv.utils.windowresize(chart.update);              return chart;         });     </script> </body> </html> 

this second char focus chart — allows user select , magnify particular part of main chart. disable it, set focusenable option false, this:

nv.addgraph(function () {     var chart = nv.models.lineplusbarchart()         .margin({             top: 30,             right: 60,             bottom: 50,             left: 70         })         .x(function (d, i) { return i; })         .y(function (d, i) { return d[1]; });         .options({focusenable: false}); // here     // ...     return chart; }); 

p.s. here's live example of chart i've used figure out answer: http://jsfiddle.net/7ms6041o/2/ focusenable option set false.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -