首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flot堆叠条形

Flot堆叠条形
EN

Stack Overflow用户
提问于 2012-01-06 21:53:20
回答 1查看 2K关注 0票数 1

因此,我有上面的flot堆叠酒吧使用flot。现在我还有一个悬停效果,当悬停在主栏中的任何栏上时,它会显示该部分的数字。我想要显示的是他们的百分比,他们是在参考当前的酒吧,而不是数字,但我看不到任何地方,我可以得到总的酒吧(即,寻找的数字是约4200基于这个酒吧)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-06 22:11:31

为了得到总数,您需要查看数据并找到与所单击项目对应的系列中的元素,然后对它们的值求和。

代码语言:javascript
复制
       <div id="placeholder" style="width:600px;height:300px;"></div>
    <div id="clickdata" ></div>


<script id="source">
$(function () {
    var d1 = [];
    for (var i = 0; i <= 10; i += 1)
        d1.push([i, parseInt(Math.random() * 30)]);

    var d2 = [];
    for (var i = 0; i <= 10; i += 1)
        d2.push([i, parseInt(Math.random() * 30)]);

    var d3 = [];
    for (var i = 0; i <= 10; i += 1)
        d3.push([i, parseInt(Math.random() * 30)]);

    var stack = 0, bars = true, lines = false, steps = false;

    function plotWithOptions() {
       return $.plot($("#placeholder"), [ d1, d2, d3 ], {
            grid: { clickable: true },
            series: {
                stack: stack,
                lines: { show: lines, fill: true, steps: steps },
                bars: { show: bars, barWidth: 0.6, hoverable: true, clickable: true }
            }
        });

    }

    var plot = plotWithOptions();

    function getTotalForIndex(index) {
        var total = parseFloat(d1[index][1]) + parseFloat(d2[index][1]) + parseFloat(d3[index][1]);
        return total;
    }

    $("#placeholder").bind("plotclick", function (event, pos, item) {
        if (item) {
            $("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ". which has total value "+ getTotalForIndex(item.dataIndex));
            plot.highlight(item.series, item.datapoint);
        }
    });
});
</script>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8758861

复制
相关文章

相似问题

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