简体   繁体   English

如何在 dc.js 中更改折线图中的线条粗细?

[英]How can you change the line thickness in a line chart in dc.js?

I would like to change the line thickness for the plotted line (not the axis), in a dc.js line chart.我想在 dc.js 折线图中更改绘制线(而不是轴)的线宽。 I guess this will be really basic, but cannot for the life of me find anything about it.我想这将是非常基本的,但在我的生活中找不到任何关于它的东西。 Not a single example that I could find changes the default thickness of the plot line.没有一个例子可以改变 plot 线的默认厚度。 Not a single question asks it.没有一个问题问它。 Color, sure.颜色,当然。 You want dotted lines?你想要虚线吗? all kind of options.各种选择。 But if you want an extra thick line or a very thin one, nothing doing.但是,如果您想要一条特别粗的线或一条非常细的线,那就什么也不做。 Please shame me with the simplicity of it.请以它的简单性让我感到羞耻。

Any SVG attribute or attribute of dc.js which can be driven by data has a function which allows you to define the encoding from data to the attribute.任何可以由数据驱动的 SVG 属性或 dc.js 的属性都有一个 function 允许您定义从数据到属性的编码。

But there are many attributes which are not driven by data.但是有很多属性不是由数据驱动的。 For these, you can use CSS styling, and it will apply to the whole chart.对于这些,您可以使用 CSS 样式,它将应用于整个图表。

To be safe and not affect the wrong elements or other stuff on the page, you can constrain the selector:为了安全且不影响页面上的错误元素或其他内容,您可以约束选择器:

.dc-chart path.line {
    stroke-width: 3px;
}

This is untested but should work.这是未经测试的,但应该可以工作。 If it does not, please comment and I'll test tomorrow.如果没有,请评论,我明天测试。

Reference: https://github.com/dc-js/dc.js/wiki/Chart-selectors参考: https://github.com/dc-js/dc.js/wiki/Chart-selectors

Use the.strokeWidth() function.使用 .strokeWidth() function。

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

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