轴标签的多级/分组使用d3 [英] Multi-Level/Grouping of Axis Labels Using d3

查看:253
本文介绍了轴标签的多级/分组使用d3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个简单的方法在d3中添加多级/分层/轴标签分组。例如,如果我有一个折线图,其中x轴横跨多个年份的月份名称,我想在月份名称下面也有年份作为标签,因此它看起来像这样。

I was wondering if there is an easy way to add multi-level/hierarchical/grouping of axis label in d3. For example, if I have a line chart with month name for x-axis spanning across multiple years, I would want to also have year as label below the month names so it looks something like this.

Oct   Nov   Dec   Jan   Feb   Mar   Apr
|_____________|   |___________________|
     2011                 2012

我知道你可以在SVG中做任何事情,我想尽可能多地使用d3,以便动态更新图表更容易。

I understand that you can do anything in SVG to make it works, but I want to use d3 as much as possible so that it's much easier to update the chart dynamically.

谢谢,
杰克

推荐答案

您可以根据喜好添加和格式化多个轴。例如 - 显示一个轴显示月份,另一个显示年份。一个基本示例: http://jsfiddle.net/Ea4mT/1/

You can add and format several axes however you like. For instance - display one axis showing months, and another showing years. A basic example: http://jsfiddle.net/Ea4mT/1/

你可能不得不稍微混乱一下,以更好的格式获得它,但它似乎是你想要完成的核心。

You might have to mess with it a little bit afterwards to get it in a more preferable format, but it seems like the core of what you are trying to accomplish.

这篇关于轴标签的多级/分组使用d3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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