react+echarts

获取返回值画echart

<ReactEcharts option={option} notMerge={true} lazyUpdate={true} />

<Button type="primary" onClick={doLine}>查询</Button>

ReactEcharts --->图表

Button--->按钮查询图表

option 值动态赋值。

const [option, setOption] = useState({})

const doCreatLine = async ()=> {
    lineOption(data)
}

const lineOption = (data: any) => {
  let option = {
      title: {
        text: 'Stacked Line',
        textStyle: {
          color: textColor
        },
        x: 'center'
      },
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        data: ['Email', 'Union Ads'],
        textStyle: {
          color: textColor
        },
        y: 'bottom'
      },
      grid: {
        left: '6%',
        right: '6%',
        bottom: '8%',
        containLabel: true
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: data.map((item: { req: any }, index: any) => {  //react 遍历写法和juqery不同
          return item.req
        }),
        axisLine: {
          lineStyle: {
            color: axisLineColor
          }
        }
      },
      yAxis: {
        type: 'value',
        axisLine: {
          lineStyle: {
            color: axisLineColor
          }
        },
        splitLine: {
          lineStyle: {
            color: splitLineColor
          }
        }
      },
      series: [
        {
          name: 'Email',
          type: 'line',
          stack: 'Total',
          data: data.map((item: { email: any }, index: any) => {
            return item.email
          })
        },
        {
          name: 'Union Ads',
          type: 'line',
          stack: 'Total',
          data: data.map((item: { UnionAds: any }, index: any) => {
            return item.UnionAds
          })
        }
      ]
    }
 setOption(option)   // option赋值,调用
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值