import * as React from 'react'; import './lineChart.scss'; import * as DataSet from 'dataset-for-g2' import { label, tickLine, line, AxisLabel, containerTpl, itemTpl, crosshairs, line1Style, line2Style } from './data'; const cols = { }; interface Props{ data:any } export default class Chart extends React.Component{ constructor(p:Props){ super(p); // const data =[{x: "2016/12/11", y: 0, y2: 0},{x: "2017/2/11", y: 9, y2: 8},{x: "2017/4/11", y: 10, y2: 20},{x: "2017/6/11", y: 11, y2: 11},{x: "2017/8/11", y: 8, y2: 2}] this.loadChart(); this.state={ BIZ:undefined } } state:{ BIZ:any } loadChart = () => { import(/* webpackChunkName: "bizcharts" */ "bizcharts").then(BIZ => { this.setState({ BIZ }); }); } callBackPut(x:number, y:number,t:number){ return { //自定义 tooltip 上显示的 title 显示内容等。 name: `${t.toString()=='y' ?'当周打赏':'当周获赏'} ${y} 元 `, title: x }; } getLineStyle=(x:string, money:number, time:string)=>{ if(time.toString()=='y'){ return line1Style; } else{ return line2Style; } } render() { const ds = new DataSet(); const dv = ds.createView().source(this.props.data); dv.transform({ type: 'fold', fields: [ 'y', 'y2' ], // 展开字段集 key: 'time', // key字段 value: 'money', // value字段 }); const {BIZ} = this.state; if(!BIZ) return null; return ( ); } }