React Nivo 虚线
React Nivo dashed line
我正在尝试创建一个 React nivo 折线图,使用虚线而不是实线。我研究过图案,但不知道如何制作图案。感谢您的帮助。
nivo 在库中提供了自定义图层功能,您可以使用它来自定义从实线到虚线的线条
这是我为您制作的代码框。
https://codesandbox.io/s/wonderful-lumiere-ouhwv?file=/src/components/LineChart.js
在 ResponsiveLine 的层中包含自定义层 属性
<ResponsiveLine
...
layers={[ ..., DashedSolidLine] }
/>
自定义路径样式
const DashedSolidLine = ({ series, lineGenerator, xScale, yScale }) => {
return series.map(({ id, data, color }, index) => (
<path
...
style={
index % 2 === 0
? {
// simulate line will dash stroke when index is even
strokeDasharray: "3, 6",
strokeWidth: 3
}
: {
// simulate line with solid stroke
strokeWidth: 1
}
}
/>
));
};
我正在尝试创建一个 React nivo 折线图,使用虚线而不是实线。我研究过图案,但不知道如何制作图案。感谢您的帮助。
nivo 在库中提供了自定义图层功能,您可以使用它来自定义从实线到虚线的线条
这是我为您制作的代码框。
https://codesandbox.io/s/wonderful-lumiere-ouhwv?file=/src/components/LineChart.js
在 ResponsiveLine 的层中包含自定义层 属性
<ResponsiveLine
...
layers={[ ..., DashedSolidLine] }
/>
自定义路径样式
const DashedSolidLine = ({ series, lineGenerator, xScale, yScale }) => {
return series.map(({ id, data, color }, index) => (
<path
...
style={
index % 2 === 0
? {
// simulate line will dash stroke when index is even
strokeDasharray: "3, 6",
strokeWidth: 3
}
: {
// simulate line with solid stroke
strokeWidth: 1
}
}
/>
));
};