[英]to How do I style an individual column / bar in C3.js?
I am new to c3.js / visualization and am trying to style the data1 bar/column in C3.js, I have the following css and can select all bars: 我是c3.js /可视化的新手,并尝试在C3.js中设置data1条/列的样式,我具有以下CSS并可以选择所有条:
#chart .c3-chart-bars .c3-shape {
stroke: black !important;
stroke-width: 2 !important;
}
And I can set the fill opacity of the bar I want to style like so: 我可以设置要设置样式的条的填充不透明度:
.c3-bars-data1 {
fill-opacity: 0 !important;
}
However, if I try to set the stroke using the same selector, nothing happens: 但是,如果我尝试使用相同的选择器设置笔划,则不会发生任何事情:
.c3-bars-data1 {
fill-opacity: 0 !important;
stroke: black !important;
stroke-weight: 1 !important;
}
Just using c3-bars-data1 I'm not able to change the fill color or any other option it seems. 仅使用c3-bars-data1我无法更改填充颜色或其他任何看起来似乎的选项。
var chart = c3.generate({
bindto: '#chart',
data: {
columns: [
['data1', -30, 200, 200, 400, -150, 250],
['data2', 130, 100, -100, 200, -150, 50],
['data3', -230, 200, 200, -300, 250, 250]
],
type: 'bar',
groups: [
['data1', 'data2']
]
},
grid: {
y: {
lines: [{
value: 0
}]
}
}
});
If you meant to set the color for all bars representing data1 (not just a single bar) you can add the colors attribute to the data definition: 如果要为代表data1的所有条形设置颜色(而不仅仅是单个条形),则可以将colors属性添加到数据定义中:
data:{
colors: {
'data1':'#FF0000'
},
...
see : http://c3js.org/reference.html#data-colors for more information 有关更多信息,请参见: http : //c3js.org/reference.html#data-colors
edit: TS mentioned he wanted styling not just color, same deal, a bit more complicated 编辑:TS提到他不仅要样式,而且要颜色,但要复杂一些
data:{
classes: {
data1: 'additional-data1-class',
data2: 'additional-data2-class',
}
...
this will add c3-target-additional-data1-class to data1 bars, which you can define in your CSS. 这会将c3-target-additional-data1-class添加到data1条中,您可以在CSS中定义。 see: http://c3js.org/reference.html#data-classes for more info. 有关更多信息,请参见: http : //c3js.org/reference.html#data-classes 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.