【发布时间】:2017-08-09 11:41:49
【问题描述】:
我正在尝试自己尝试 nvd3 散点图示例。我没有收到任何错误,但图表没有填充。
当我尝试访问屏幕时,我得到了一个空白网页。甚至我现有的其他内容都没有了。有没有人设法让散点图启动并运行?如果您能分享一个工作示例,我将不胜感激。
#html
<script>
$(document).ready(function(){
nv.addGraph(function() {
var chart = nv.models.scatterChart()
.showDistX(true) //showDist, when true, will display those little distribution lines on the axis.
.showDistY(true)
.color(d3.scale.category10().range());
//Axis settings
chart.xAxis.tickFormat(d3.format('.02f'));
chart.yAxis.tickFormat(d3.format('.02f'));
var myData = randomData(4,40);
d3.select('#chart svg')
.datum(myData)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
/**************************************
* Simple test data generator
*/
function randomData(groups, points) { //# groups,# points per group
var data = [],
shapes = ['circle', 'cross', 'triangle-up', 'triangle-down', 'diamond', 'square'],
random = d3.random.normal();
for (i = 0; i < groups; i++) {
data.push({
key: 'Group ' + i,
values: []
});
for (j = 0; j < points; j++) {
data[i].values.push({
x: random()
, y: random()
, size: Math.random() //Configure the size of each scatter point
, shape: (Math.random() > 0.95) ? shapes[j % 6] : "circle" //Configure the shape of each scatter point.
});
}
}
return data;
}
});
【问题讨论】:
-
尝试将您的代码放入fiddle。它易于调试并为您提供帮助。
-
听起来你可能有一个 JS 错误。您在控制台中看到了什么?同意 JSFiddle 或 Plunkr 会有所帮助。
标签: python django d3.js nvd3.js scatter-plot