Echarts学习之路3(在react中使用)

摘要:
安装:npminstallcharacters--savedemoimportReact,{Component}from“react”//从“charts/lib/charts”导入ECharts主模块导入图表//导入“charts/lib/chart/bar”//导入提示框和标题组件导入“charts/lib/Component/tool”

安装:

npm install echarts --save

demo

import React, { Component } from 'react';
// 引入 ECharts 主模块
import echarts from 'echarts/lib/echarts';
// 引入柱状图
import  'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
class App extends Component {
  componentDidMount() {
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        // 绘制图表
        myChart.setOption({
            title: { text: 'ECharts 入门示例' },
            tooltip: {},
            xAxis: {
                data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        });
    }
    render() {
        return (
            <div   style={{  400, height: 400 }}></div>
        );
    }
  }

export default App;

免责声明:文章转载自《Echarts学习之路3(在react中使用)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇unittest与pytest的区别【C#上位机必看】你们想要的练手项目来了下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

React onClick点击事件传参三种写法

第一种 用bind绑定,调用是作为第二个参数传递,不用显示传递事件对象,定义方法时,事件对象作为最后一个参数传入 class Test extends React.Component{ constructor(props){ super(props) } render(){ return( <button o...

React 产线去掉 console.log 打印

打开 config / webpack.config.js , 搜索 optimization module.exports = { optimization:{ minimizer: [ new TerserPlugin({ sourceMap:false, terserOptions:{ compress:{...

arcGis react中自定义模板

import React from 'react'; import './index.less'; import { mapContext } from 'contexts/map'; import { Checkbox } from 'antd'; import esriConfig from 'gisConfig/esri.config'; impo...

react + antd form表单验证自定义验证validator根据后台接口判断验证

有时候表单中的某些字段是需要调用后台接口验证,比如账号,ID之类的.这时候页面需要根据后台返回结果提示 //验证账号是否已经被添加过 const checkAccount = (value: string | number) =>{ // 这个是rules自定义的验证方法 return new Promise((resolve, re...

web worker在react项目中的使用

新建一个worker.js文件,编写worker子线程脚本,代码如下: const workercode = () => { self.onmessage = function(e) { console.log('Message received from main script'); var workerResult = 'R...

使用npx创建react+typescript项目

1. 创建ts项目 npx create-react-app xxx --template typescript 2. 配置prettier vscode 安装插件 右键选项 选择prettier 3. 配置环境变量 根目录下新建下图文件 生产环境文件:.env 测试环境文件:.env.development 注意:环境变量需要以REACT_APP_...