简体   繁体   English

D3带时间的堆积条形图

[英]D3 stacked bar chart with time

I have problem working with d3 and date time. 我在使用d3和日期时间时遇到问题。 Is there an example that shows stacked bar chart with time dimension ? 是否有一个示例显示具有时间维度的堆叠条形图? I would like to visualize users' activities such as riding on a bus, walking, etc. as a bar chart. 我想将用户的活动(如乘坐公共汽车,步行等)可视化为条形图。 The existing ones are based on numbers and really complicated to understand. 现有的数字是基于数字的,并且很难理解。 I found this one https://gist.github.com/anotherjavadude/2940908 which seems better, but still not clear for me. 我发现了一个https://gist.github.com/anotherjavadude/2940908 ,它看起来更好,但对我来说仍然不清楚。

I found Stacked bar-charts on time scale using D3 which seems to fit your needs. 我发现使用D3在时间刻度上堆积了条形图 ,这似乎很适合您的需求。

Anyways, I'd rather go with Highcharts and use its stacked bar charts as time series. 无论如何,我宁愿选择Highcharts并将其堆积的条形图用作时间序列。

On the JSfiddle below you can see exactly how I did it: 在下面的JSfiddle上,您可以确切地看到我是如何做到的:

http://jsfiddle.net/fwuensche/y1w9nnod/3/ http://jsfiddle.net/fwuensche/y1w9nnod/3/

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'My energy consumption'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 
                         'Jun', 'Jul', 'Aug', 'Sep', 'Oct']
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Consumption [KWh]'
            },
            stackLabels: {
                enabled: true,
                style: {
                    fontWeight: 'bold',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                }
            }
        },

        // series data goes here

    });
});

Hope it helps! 希望能帮助到你!

这是一个基于日期的条形图示例: http : //bl.ocks.org/mbostock/1134768

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM