React中使用echarts


1.安裝相關的依賴:

cnpm i react-for-echarts -S

cnpm i echarts -S

2.使用方法:

頁面引入:

import ReactEcharts from 'echarts-for-react';

1).使用組件方式

class EchartsTest extends Component{

  render(){

        const option = {
            xAxis: {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: [820, 932, 901, 934, 1290, 1330, 1320],
                type: 'line'
            }]
        };
    return(
      <ReactEcharts  option={option} style={{height:'200px',width:'100%'}}/>
    )
  }
}

2).echarts相關的配置項目

const option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [{
    data: [820, 932, 901, 934, 1290, 1330, 1320],
    type: 'line'
  }]
};
const EchartsTest =()=>(
    <ReactEcharts
        option={option}
        style={{height:'220px',width:'100%'}}
    ></ReactEcharts>
);

最后導出

export default EchartsTest;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM