我正在使用chartist.js
制作图表组件。我正在将scss文件导入到我的组件中,但scss样式不起作用。检查以下代码:
chart.js之:
import React, { Component } from 'react';
import ChartistGraph from "react-chartist";
import Legend from "chartist-plugin-legend";
import './piechart.scss';
let options = {
width:400,
height:500,
labelInterpolationFnc: function(value) {
return value[0]
},
plugins: [
Legend()
]
};
class Chart extends Component {
render(){
return(
<div>
<div className="center">
<ChartistGraph data={data} options={options} type="Pie"/>
</div>
</div>
)}
}
export default Chart;
piechart.scss:
.ct-legend {
position: relative;
z-index: 10;
li {
position: relative;
padding-left: 23px;
margin-bottom: 3px;
}
li:before {
width: 12px;
height: 12px;
position: absolute;
left: 0;
content: '';
border: 3px solid transparent;
border-radius: 2px;
}
li.inactive:before {
background: transparent;
}
&.ct-legend-inside {
position: absolute;
top: 0;
right: 0;
}
@for $i from 0 to length($ct-series-colors) {
.ct-series-#{$i}:before {
background-color: nth($ct-series-colors, $i + 1);
border-color: nth($ct-series-colors, $i + 1);
}
}
}
请检查下面的屏幕截图,我没有按照要求获得传说 - &gt; https://codeyellowbv.github.io/chartist-plugin-legend/
答案 0 :(得分:1)
sass / scss需要预处理。您必须弹出项目并添加所需的处理,以下是一些示例:
https://medium.com/@Connorelsea/using-sass-with-create-react-app-7125d6913760
https://medium.com/front-end-hacking/how-to-add-sass-or-scss-to-create-react-app-c303dae4b5bc