列按组堆积图表 [英] Column stacked chart by groups

查看:113
本文介绍了列按组堆积图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张柱形图,显示当前和过去几年的耗电量。现在这种消费来自不同的来源,所以我想绘制这些值显示堆叠值的多个列。

I have a column chart that shows power consumption in current and previous years. Now this consumption comes from different sources, so I would like to chart these values in multiple columns that show stacked values.

我使用谷歌图表,但设置<$ options数组中的c $ c> isStacked 参数为 true 只是堆栈特定行的每个值。我想要做的是这样的:

I am using google chart, but setting the isStacked parameter to true in the options array just stacks every single value for a specific row. What I want to do achieve is something like this:

即,具有多个堆积列的行。这可以通过Google Chart API实现吗?

That is, rows with multiple stacked columns. Is this even possible with Google Chart API?

推荐答案

这可以通过kludge实现:

This is doable with a kludge:

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Country', 'Cars', 'Trucks'],
    ['', null, null],
    ['US', 15, 15],
    ['Canada', 17, 17],
    ['Europe', 13, 13],
    ['Mexico', 16, 16],
    ['Asia', 20, 20],
    ['', null, null],
    ['US', 15, 15],
    ['Canada', 17, 17],
    ['Europe', 13, 13],
    ['Mexico', 16, 16],
    ['Asia', 20, 20],
    ['', null, null],
    ['US', 15, 15],
    ['Canada', 17, 17],
    ['Europe', 13, 13],
    ['Mexico', 16, 16],
    ['Asia', 20, 20],
    ['', null, null],
    ['US', 15, 15],
    ['Canada', 17, 17],
    ['Europe', 13, 13],
    ['Mexico', 16, 16],
    ['Asia', 20, 20],
    ['', null, null],
  ]);

  // Create and draw the visualization.
  new google.visualization.ColumnChart(document.getElementById('visualization')).
      draw(data,
           {isStacked:true, width:800, hAxis: {showTextEvery:1, slantedText:true}}
      );
}

这可能不是这样做的好方法。基本上,您试图让单个图表显示太多的信息,并且将您的数据拆分为多个图表要好得多。例如,您可以使用域角色,或者您可以使用一个折线图可以比较卡车和汽车之间的差异(目前由于基线不同,目前您不能这样做)。您还可以将不同国家的汽车或卡车作为标准柱形图(不堆积)进行比较。您可以使用图表互动来允许用户选择哪些数据他们想看。看起来您正在尝试重新创建一个与交互式技术没有互动性的现有Excel图表,所以最好的方法是重新考虑如何使用它,以便能够通过技术变化进行交互。

This is probably not a great way of doing this. Basically, you are trying to make a single chart show too much information and would be far better off splitting up your data in to multiple charts. For instance, you can use domain roles, or you can just use a line chart to be able to compare the difference between trucks and cars (which you can't currently do because of the different baselines). You can also compare different countries on just cars or trucks as a standard column chart (not stacked). You can use chart interaction to allow users to pick what data they want to see. It looks like you are trying to recreate an existing Excel chart which isn't interactive with an interactive technology, so the best thing is likely to rethink how it should be used given the ability to interact due to the shift in technology.

这篇关于列按组堆积图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆