欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

React項目搭建與Echarts工具使用詳解

 更新時間:2023年05月09日 10:24:34   作者:愛打羽球的碼猿  
這篇文章主要介紹了React項目搭建與Echarts工具使用詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

一、React項目快速搭建

1、新建文件夾

在這里插入圖片描述

2、直接在對應目錄輸入 cmd ,打開終端

在這里插入圖片描述

3、執(zhí)行指令完成React應用建立

npx create-react-app react_echarts_demo

在這里插入圖片描述

cd react_echarts_demo
npm start

在這里插入圖片描述

在這里插入圖片描述

二、React項目結構和分析

終端對應目錄下輸入 code . 打開 vs code

1、刪除多于文件,使得結構清晰

在這里插入圖片描述

2、刪除剩余文件中多于的引用內(nèi)容

在這里插入圖片描述

3、使用vs code打開終端,運行項目

在這里插入圖片描述

在這里插入圖片描述

三、Echarts工具使用

1、npm安裝依賴

npm install echarts --save
npm install --save echarts-for-react

2、簡單折線圖

使用 echarts-for-react

在這里插入圖片描述

引用代碼

import React from 'react';
import ReactDOM from 'react-dom/client';
import LineCharts  from './LineCharts';

const root = ReactDOM.createRoot(document.getElementById('root'));

root.render(
  <div> 
    <h1> 簡單折線圖</h1>
    <LineCharts></LineCharts>
  </div>
);

組件代碼

import React, {Component} from 'react';
import ReactECharts from 'echarts-for-react';


// 在此組件中繪制一個簡單的折線圖
export default class LineCharts  extends Component{
  // 返回折線圖的配置對象
  option = {
    xAxis: {
      type: 'category',
      data: ['A', 'B', 'C']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [120, 200, 150],
        type: 'line'
      }
    ]
  };

  render() {
    return(
      <div>
        <ReactECharts option={this.option} />
      </div>
    )
  }
}

3、燃盡圖 使用echarts

在這里插入圖片描述

代碼如下:

index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import LineEChartsDemo  from './LineEchartsDemo';

const root = ReactDOM.createRoot(document.getElementById('root'));

root.render(
  <div> 
    <h1>燃盡圖</h1>
    <LineEChartsDemo></LineEChartsDemo>
  </div>
);

LineEchartsDemo.jsx

import React, { Component } from 'react'
import LineECharts from './LineECharts'


class LineEchartsDemo extends Component{

  constructor(props) {
    super(props)
    this.state = {
	    data: {
	      x: ['2023-03-18', '2023-03-19', '2023-03-20', '2023-03-22', '2023-03-23', '2023-03-24', '2023-03-25'],
	      y: [100, 93, 80, 70, 53, 36, 0]
	    }
    }
  }
  componentDidMount() { }
  render() {
     	return (<LineECharts data={this.state.data} yname="進度/%" />  )
  }
}

export default LineEchartsDemo 

LineECharts.jsx

import React, {Component} from 'react';

import * as echarts from 'echarts';


export default class LineECharts  extends Component{
  constructor(props) {
    super(props)
    this.state = {
    }
  }

  // 掛載完成之后,因為React初始化echarts時長寬可能會獲取到頂層,所以延遲200去生成,不影響視覺效果
  componentDidMount() {
    setTimeout(() => {
      this.initEchart(this.props.data)
    }, 200)
  }

  // 更新props以后調(diào)用
  componentWillReceiveProps(newProps) {
    this.initEchart(newProps.data)
  }

  initEchart = (data) => {
    let myEcharts = echarts.init(this.echartsBox)
    let option = {
      
      title: {
        text: this.props.title || '',
        left: 'center',
        top: '0'
      },
      tooltip: {
        show: true,
        trigger: 'axis',
        
        formatter: '<br/>進度:{c}%',
        extraCssText: 'box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);'
      },
      xAxis: {
        type: 'category',
        data: data.x,  
      },
      yAxis: {
        name: this.props.yname,
        nameGap: 15,
        position: 'left',
        axisLabel: {
          formatter: '{value}'
        }
      },
      series: [{
        name: '匯總',
        type: 'line',
        data: data.y,
        smooth: false,
        lineStyle: {
          color: '#00CC99',
          width: 2
        },
      
      }]
    }
    myEcharts.setOption(option)
    myEcharts.on('finished', () => {
      myEcharts.resize()
    })
  }

  render() {
    return (
      <div ref={(c) => { this.echartsBox = c }} style={{ width: '500px', height: '500px' }} />
    )
  }
}

4、不同的圖形,Echarts官網(wǎng)找對應Option內(nèi)容復制即可

在這里插入圖片描述

option = {
  xAxis: {
    data: ['A', 'B', 'C', 'D', 'E']
  },
  yAxis: {},
  series: [
    {
      data: [10, 22, 28, 43, 49],
      type: 'line',
      stack: 'x'
    },
    {
      data: [5, 4, 3, 5, 10],
      type: 'line',
      stack: 'x'
    }
  ]
};

到此這篇關于React項目搭建與Echarts工具使用的文章就介紹到這了,更多相關React使用Echarts內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • React中事件綁定this指向三種方法的實現(xiàn)

    React中事件綁定this指向三種方法的實現(xiàn)

    這篇文章主要介紹了React中事件綁定this指向三種方法的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • 一看就懂的ReactJs基礎入門教程-精華版

    一看就懂的ReactJs基礎入門教程-精華版

    現(xiàn)在最熱門的前端框架有AngularJS、React、Bootstrap等。自從接觸了ReactJS,ReactJs的虛擬DOM(Virtual DOM)和組件化的開發(fā)深深的吸引了我,下面來跟我一起領略ReactJs的風采吧~~ 文章有點長,耐心讀完,你會有很大收獲哦
    2021-04-04
  • 詳解React開發(fā)必不可少的eslint配置

    詳解React開發(fā)必不可少的eslint配置

    本篇文章主要介紹了詳解React開發(fā)必不可少的eslint配置,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • 詳解Redux的工作流程

    詳解Redux的工作流程

    這篇文章主要介紹了Redux的工作流程,redux是一個專門用于做狀態(tài)管理的JS庫,它可以在react、angular、vue等項目中,但基本與react配合使用,需要的朋友可以參考下
    2022-08-08
  • react-native封裝插件swiper的使用方法

    react-native封裝插件swiper的使用方法

    這篇文章主要介紹了react-native封裝插件swiper的使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • React-Native中props具體使用詳解

    React-Native中props具體使用詳解

    本篇文章主要介紹了React-Native中props具體使用詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • 詳解react關于事件綁定this的四種方式

    詳解react關于事件綁定this的四種方式

    這篇文章主要介紹了詳解react關于事件綁定this的四種方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • React中的Props類型校驗和默認值詳解

    React中的Props類型校驗和默認值詳解

    這篇文章主要為大家詳細介紹了React中的Props類型校驗和默認值,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • 使用React-Window實現(xiàn)虛擬滾動效果的示例代碼

    使用React-Window實現(xiàn)虛擬滾動效果的示例代碼

    React-Window?是一個為?React?應用程序中高效渲染大數(shù)據(jù)集而設計的庫,它基于窗口化或虛擬化的原則運行,本文將使用React-Window實現(xiàn)虛擬滾動效果,感興趣的可以了解下
    2024-01-01
  • 快速創(chuàng)建React項目并配置webpack

    快速創(chuàng)建React項目并配置webpack

    這篇文章主要介紹了創(chuàng)建React項目并配置webpack,在這里需要注意,Create?React?App?requires?Node?14?or?higher.需要安裝高版本的node,本文給大家介紹的非常詳細,需要的朋友參考下吧
    2022-01-01

最新評論