Nvd3js - TypeError: data.map не является функцией

Я пытаюсь отобразить график Stacked nvd3js (http://nvd3.org/examples/stackedArea.html) и продолжает получать эту ошибку:

state.disabled = data.map (функция (d) {возврат !! d.disabled});

сложены... hart.js (строка 87, столбец 6))

мой пример json:

var data = [
    {
"key":"Key1","values":
[[1009756800000,858666000],
[1041292800000,910926000],
[1072828800000,1073489000],
[1104451200000,1333281000],
[1135987200000,2168985000],[
1167523200000,3185387000],
[1199059200000,3303486000],
[1230681600000,4372067000],
[1262217600000,8688161000],
[1293753600000,12189267000],
[1325289600000,16442852000],
[1356912000000,18622678000],
[1009756800000,2551000],
[1041292800000,2484000],
[1072828800000,2416000], 
]
} 
,
{
"key":"Key2","values":
[[1104451200000,9348000],
[1135987200000,12642000],
[1167523200000,12127000],
[1199059200000,11661000],
[1230681600000,33554000],
[1262217600000,32146000],
[1293753600000,30462000],
[1325289600000,177327000],
[1356912000000,177882000],
[1009756800000,0],
[1041292800000,0],
[1072828800000,0],
[1104451200000,0],
[1135987200000,0],
[1167523200000,0], 
] 
} 
,
{
"key":"Key3","values":
[[1009756800000,185679000],
[1041292800000,236607000],
[1072828800000,150931000],
[1104451200000,323469000],
[1135987200000,281266000],
[1167523200000,309607000],
[1199059200000,557171000],
[1230681600000,787080000],
[1262217600000,1084286000],
[1293753600000,1129885000],
[1325289600000,1420153000],
[1356912000000,3315623000],
[1009756800000,193891000],
[1041292800000,253113000],
[1072828800000,296447000], 
] 
}
];

и код nvd3js:

//NVd3js
function defaultChartConfigBS(container, data, useGuideline) {
  if (useGuideline === undefined) useGuideline = true;
  nv.addGraph(function() {
    var chart;
    chart = nv.models.stackedAreaChart()
                  .useInteractiveGuideline(useGuideline)
                  .x(function(d) { return d[0] })
                  .y(function(d) { return d[1] })
                  .useInteractiveGuideline(true)    //Tooltips which show all data points. Very nice!
                  .rightAlignYAxis(false)      //Let's move the y-axis to the right side.
                  .transitionDuration(500)
                  .showControls(true)       //Allow user to choose 'Stacked', 'Stream', 'Expanded' mode.
                  .clipEdge(true)
                    ;

    chart.xAxis
        .tickFormat(function(d) { return d3.time.format('%x')(new Date(d)) });


    chart.yAxis
        .tickFormat(d3.format(',.2f'));

    d3.select('#' + container + ' svg')
          .datum(data)
           // .datum( [data()[0].values] ) tried the hack from stack - didnt help
        .transition().duration(20).call(chart);

    nv.utils.windowResize(chart.update);


    return chart;
  });
}

person digitalM    schedule 21.08.2014    source источник


Ответы (1)


В коде nvd3js:

Вместо

chart = nv.models.stackedAreaChart()
              .useInteractiveGuideline(useGuideline)
              .x(function(d) { return d[0] })
              .y(function(d) { return d[1] })
              .useInteractiveGuideline(true)    //Tooltips which show all data points. Very nice!
              .rightAlignYAxis(false)      //Let's move the y-axis to the right side.
              .transitionDuration(500)
              .showControls(true)       //Allow user to choose 'Stacked', 'Stream', 'Expanded' mode.
              .clipEdge(true)
                ;

Вы можете использовать :

chart = nv.models.stackedAreaWithFocusChart();
                         chart.width(600).height(500)                            
                         .x(function (d) {
                             return d[0]
                         })
                         .y(function (d) { return d[1] })
                         .color(keyColor);

а также вместо

  d3.select('#' + container + ' svg')
      .datum(data)
       // .datum( [data()[0].values] ) tried the hack from stack - didnt help
    .transition().duration(20).call(chart)

Вы можете использовать :

d3.select('#' + container + ' svg')
                 .datum(data)
               .call(chart);
person Manjunath Raddi    schedule 04.12.2014
comment
Есть ли шанс объяснить, почему? - person Adam Copley; 12.02.2016
comment
Да. Здесь поможет объяснение. Без внимательного чтения непонятно, что изменилось. Не могли бы вы уточнить, какие изменения актуальны и почему? - person Brylie Christopher Oxley; 14.06.2017