D3Plus散点图X轴字符串

时间:2018-09-25 15:05:45

标签: javascript string d3.js d3plus

我想知道是否可以像这样将“字符串”传递到D3Plus散点图的X轴:

 // sample data array
  var sample_data = [
    {"value": 100, "weight": .45, "type": "alpha"},
    {"value": 70, "weight": .60, "type": "beta"},
    {"value": 40, "weight": -.2, "type": "gamma"},
    {"value": 15, "weight": .1, "type": "delta"}
  ]
  // instantiate d3plus
  var visualization = d3plus.viz()
    .container("#viz")  // container DIV to hold the visualization
    .data(sample_data)  // data to use with the visualization
    .type("scatter")    // visualization type
    .id("type")         // key for which our data is unique on
    .x("type")         // key for x-axis
    .y("weight")        // key for y-axis
    .draw()             // finally, draw the visualization!

jsfiddle

在此配置下,我遇到此错误 未捕获的TypeError:testScale.invert不是函数

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

  // instantiate d3plus
  var visualization = d3plus.viz()
    .container("#viz")  // container DIV to hold the visualization
    .data(sample_data)  // data to use with the visualization
    .type("scatter")    // visualization type
    .id("type")         // key for which our data is unique on
    .x("value")         // key for x-axis
    .y("weight")        // key for y-axis
    .draw()             // finally, draw the visualization!