我试图在我的一个项目中使用python 3的linePlusBarWithFocusChart。但是y4数据,焦点栏上的数据显示如下所示:
http://i.stack.imgur.com/ntJNW.png
如您所见,数据没有正确表示。以下是生成的脚本:
<script type="text/javascript">
nv.addGraph(function() {
var chart = nv.models.linePlusBarWithFocusChart();
chart.margin({top: 30, right: 60, bottom: 50, left: 70})
.x(function(d,i) { return i });
chart.height(350);
chart.color(d3.scale.category10().range());
chart.y2Axis
.tickFormat(function(d) { return d3.format(',.2f')(d) });
chart.x2Axis
.tickFormat(function(d) {
var dx = data_linePlusBarWithFocusChart[0].values[d] && data_linePlusBarWithFocusChart[0].values[d].x || 0;
return d3.time.format('%d %b %Y')(new Date(dx));
});
chart.y4Axis
.tickFormat(function(d) { return d3.format(',.2f')(d) });
chart.y3Axis
.tickFormat(d3.format(',f'));
chart.xAxis
.tickFormat(function(d) {
var dx = data_linePlusBarWithFocusChart[0].values[d] && data_linePlusBarWithFocusChart[0].values[d].x || 0;
if (dx > 0) { return d3.time.format('%d %b %Y')(new Date(dx)) }
return null;
});
chart.y1Axis
.tickFormat(d3.format(',.4f'));
chart.bars.forceY([0]);
chart.tooltipContent(function(key, y, e, graph) {
var x = d3.time.format('%d %b %Y')(new Date(parseInt(graph.point.x)));
var y = String(graph.point.y);
if(key.indexOf('Sentiment Rate') > -1 ){
var y = String(graph.point.y) ;
}
if(key.indexOf('User Rating') > -1 ){
var y = String(graph.point.y) ;
}
tooltip_str = '<center><b>'+key+'</b></center>' + y + ' on ' + x;
return tooltip_str;
});
chart.showLegend(true);
d3.select('#linePlusBarWithFocusChart svg')
.datum(data_linePlusBarWithFocusChart)
.transition().duration(500)
.attr('height', 350)
.call(chart);
return chart;
});
</script>用于生成上述脚本的代码是:
type = "linePlusBarWithFocusChart"
chart = linePlusBarWithFocusChart(name=type, height=350, x_is_date=True, x_axis_format="%d %b %Y",
color_category="category10")
kwargs = {}
kwargs['bar'] = True
extra_serie = {"tooltip": {"y_start": "", "y_end": ""}}
chart.add_serie(name="", y=ydata, x=xdata, extra=extra_serie, **kwargs)
extra_serie = {"tooltip": {"y_start": "", "y_end": ""}}
chart.add_serie(name="", y=ydata2, x=xdata, extra=extra_serie)
chart.buildhtml()有人能告诉我我做错了什么吗!!
发布于 2013-11-21 11:23:35
您的上下文图中的数据看起来就像是完全不正常。您所需要做的就是在将数据传递给NVD3之前对其进行排序。
https://stackoverflow.com/questions/20118944
复制相似问题