|
@@ -6,26 +6,55 @@ import echarts from 'echarts';
|
|
|
class ChartItem extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
- this.drawChart = this.drawChart.bind(this);
|
|
|
+ this.getContainers = this.getContainers.bind(this);
|
|
|
+ }
|
|
|
+ getContainers(){
|
|
|
+ const {data} = this.props;
|
|
|
+ let arr = [];
|
|
|
+ arr = data&&data.map((it,i)=>{
|
|
|
+ return <Chart data={it} index={i}/>
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+ componentDidMount(){
|
|
|
+ const {initFn} = this.props;
|
|
|
+ initFn&&initFn();
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ const {title,data } = this.props;
|
|
|
+ return <div className={style['assess-item']}>
|
|
|
+ <h2>{title}</h2>
|
|
|
+ <div className={style['item-content']}>
|
|
|
+ {this.getContainers()}
|
|
|
+ </div>
|
|
|
+ </div>;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+class Chart extends Component{
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.drawChart = this.drawChart.bind(this);
|
|
|
}
|
|
|
- drawChart(id){
|
|
|
+ drawChart(){
|
|
|
+ const {index,data} = this.props;
|
|
|
+ const id = 'chart'+index;
|
|
|
var myChart = echarts.init(document.getElementById(id));
|
|
|
|
|
|
// 指定图表的配置项和数据
|
|
|
var option = {
|
|
|
tooltip: {},
|
|
|
legend: {
|
|
|
- data:['销量']
|
|
|
+ data:[data.itemName]
|
|
|
},
|
|
|
xAxis: {
|
|
|
- data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
|
|
|
+ data: data.creatTime
|
|
|
},
|
|
|
yAxis: {},
|
|
|
series: [{
|
|
|
- name: '销量',
|
|
|
+ name: data.itemName,
|
|
|
type: 'line',
|
|
|
- data: [5, 20, 36, 10, 10, 20]
|
|
|
+ data: data.indexValue
|
|
|
}]
|
|
|
};
|
|
|
|
|
@@ -33,18 +62,10 @@ class ChartItem extends Component {
|
|
|
myChart.setOption(option);
|
|
|
}
|
|
|
componentDidMount(){
|
|
|
- this.drawChart('chart1');
|
|
|
- this.drawChart('chart2');
|
|
|
+ this.drawChart();
|
|
|
}
|
|
|
- render() {
|
|
|
- const {title,data } = this.props;
|
|
|
- return <div className={style['assess-item']}>
|
|
|
- <h2>{title}</h2>
|
|
|
- <div className={style['item-content']}>
|
|
|
- <div className={style["chart-box"]} id={'chart1'}></div>
|
|
|
- <div className={style["chart-box"]} id={'chart2'}></div>
|
|
|
- </div>
|
|
|
- </div>;
|
|
|
+ render(){
|
|
|
+ return <div className={style["chart-box"]} id={'chart'+this.props.index}></div>
|
|
|
}
|
|
|
}
|
|
|
|