首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有焦点图错误的python-nvd3 3 lineplusbarwithfocus

具有焦点图错误的python-nvd3 3 lineplusbarwithfocus
EN

Stack Overflow用户
提问于 2013-11-21 10:54:07
回答 1查看 322关注 0票数 0

我试图在我的一个项目中使用python 3的linePlusBarWithFocusChart。但是y4数据,焦点栏上的数据显示如下所示:

http://i.stack.imgur.com/ntJNW.png

如您所见,数据没有正确表示。以下是生成的脚本:

代码语言:javascript
复制
<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>

用于生成上述脚本的代码是:

代码语言:javascript
复制
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()

有人能告诉我我做错了什么吗!!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-21 11:23:35

您的上下文图中的数据看起来就像是完全不正常。您所需要做的就是在将数据传递给NVD3之前对其进行排序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20118944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档