D3-用于设置类名的三元运算符 [英] D3 - ternary operator to set class name

查看:38
本文介绍了D3-用于设置类名的三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有个笨拙的人- https://plnkr.co/edit/qDi8bm3xh3hdaV059AXX?p=预览

I have a plunker here - https://plnkr.co/edit/qDi8bm3xh3hdaV059AXX?p=preview

我有一个带有两组条形图的图表.

I have a chart with two sets of bars.

这些条使用三元运算符着色,并使用数组中的颜色.

The bars are coloured using a ternary operator and colours from an array.

我想在条形图上设置不透明度和填充模式,因此需要在条形图上添加类.

I'd like to set an opacity and fill pattern on the bars so need to add classes to the bars.

如何使用三元运算符向栏添加类.

How can I use the ternary operator to add classes to the bars.

.style('fill', (d, i) => {
    return i % 2 ? colors[1] : colors[0]
})

推荐答案

.attr('class', (d, i) => {
    return i % 2 ? 'bar-fill' : 'bar-opacity'
})

这篇关于D3-用于设置类名的三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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