如何在域中显示重复值 [英] How to show duplicate values in the domain

查看:82
本文介绍了如何在域中显示重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据即将到来的值创建条形图,它应按原样显示所有标签.条形图在本质上是分组的.

I am trying to create a bar chart based on the values that are coming, it should show all the label as it is. The bar chart is grouped in nature.

我能够创建其中的大多数内容,但是不知何故价值标签来之不易.

I am able to create most of it, but somehow value labels are not coming properly.

["July 02,2017", "July 09,2017", "July 02,2017", "July 12,2017"]

当前scale.ordinal正在删除重复值,并按以下方式设置标度:

Currently scale.ordinal is removing the duplicate values and making scale set like:

["July 02,2017", "July 09,2017", "July 12,2017"] 

哪个会扰乱图表视图.

如何在x轴上按原样显示重复值?

How can I show duplicate values in x-axis as it is?

JsFiddle

推荐答案

D3使用域的数学概念图像来表示比例的范围和范围.因此,域值应为唯一.

D3 uses the mathematical concept of domain and image for the domain and range of the scales. Therefore, domain values should be unique.

您的解决方法是在数据数组中创建另一个这样的属性,该属性使用每个对象的索引来创建一个方便地命名为index的属性:

A workaround in your case is creating another property in your data array, like this, which uses the index of each object to create a property conveniently named index:

data.forEach(function(d, i) {
    d.index = i
})

然后,将该属性(具有唯一值)用于您的x缩放域.

Then, use that property (which has unique values) for the domain of your x scale.

此外,您还必须更改x刻度的刻度,这可以通过tickFormat进行:

Also, you'll have to change the ticks for the x scale, which you can do with tickFormat:

.tickFormat(function(d, i) {
    return data[i].Groups
});

以下是更新的小提琴: http://jsfiddle.net/wujtnomh/

Here is the updated fiddle: http://jsfiddle.net/wujtnomh/

这篇关于如何在域中显示重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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