简体   繁体   English

子弹图表在D3.js中打勾和标签

[英]Bullet chart ticks & labels in D3.js

I'm trying to blend the following two "official" D3 bullet chart examples into one: 我正在尝试将以下两个“官方”D3子弹图示例合并为一个:

http://bl.ocks.org/mbostock/4061961 http://bl.ocks.org/mbostock/4061961

在此输入图像描述

http://boothead.github.io/d3/ex/bullet.html http://boothead.github.io/d3/ex/bullet.html

在此输入图像描述

I get the former to work locally, and I did manage to "plug" the JS code of the latter in by replacing "d3.chart.bullet" with "d3.bullet" (and re-referencing the DOM objects and "randomize" event listeners). 我让前者在本地工作,我确实设法通过用“d3.bullet”替换“d3.chart.bullet”来“插入”后者的JS代码(并重新引用DOM对象和“随机化”)事件监听器)。

However, compatibility with the local, label-type ".ticks" call is broken that way. 但是,与本地标签类型“.ticks”调用的兼容性就是这样。 In an ideal world I'd like to have the equidistant ticks at the bottom, and local "data label ticks" with a slightly different styiling at the top of the bullet. 在一个理想的世界里,我希望在底部有等距的刻度,当地的“数据标签刻度”在子弹的顶部有一个稍微不同的样式。

Is that possible at all? 这有可能吗? I'm beginning to doubt it, as the D3 minor versions seem to differ (both v2.x, which is good since I need nvd3 compatibility). 我开始怀疑它,因为D3次要版本似乎不同(两者都是v2.x,这是好的,因为我需要兼容nvd3)。 Any idea of how I could achieve my objective nevertheless, eg by resorting to "proper" data labels not hinging on a .ticks call? 不管怎么说,我是如何实现自己的目标的,例如通过诉诸“正确”的数据标签,而不是依赖于.ticks通话? Thanks! 谢谢!

OK, so first for the confusion resolution. 好的,首先是混淆解决方案。 In this example: 在这个例子中:

http://boothead.github.io/d3/ex/bullet.html http://boothead.github.io/d3/ex/bullet.html

two different libraries make the magic happen - d3.js in version 2.1, and d3.chart.js. 两个不同的库使魔术发生 - 版本2.1中的d3.js和d3.chart.js。 The issue occurs when saving the entire example locally, as browsers apparently only consider the first dot in the filename for handling the extension. 在本地保存整个示例时会出现问题,因为浏览器显然只考虑文件名中的第一个点来处理扩展。 Hence locally, d3.chart.js becomes d3_002.js, making it appear to be a second instance of D3 v2. 因此在本地,d3.chart.js变为d3_002.js,使其看起来像是D3 v2的第二个实例。 Moving it out leads to code failure, of course. 当然,将其移出会导致代码失败。

Lesson learned: always look at the original naming convention in the original source. 获得的经验:始终查看原始源中的原始命名约定。 I'll update this answer once I've achieved my "ideal world" solution. 一旦我实现了“理想世界”解决方案,我就会更新这个答案。

EDIT: Still working on it, the key is somewhere in the d3.chart.js. 编辑:仍在努力,关键是在d3.chart.js的某个地方。 At least I got started and overcame my initial problem, so I'll accept it as an answer. 至少我开始并克服了我最初的问题,所以我会接受它作为答案。

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

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