html前端 echarts图表使用详解

本文介绍了Echarts的官方资源及菜鸟教程,并提供了详细的CDN引用和配置示例,包括创建图表实例、设置图表选项,如X轴、Y轴、线型图、标记点和线以及提示信息等。通过示例展示了如何在网页中实现数据可视化的Echarts基本用法。
摘要由CSDN通过智能技术生成

1 echarts 介绍

官网:https://echarts.apache.org/

菜鸟教程

2 使用

2.1 CDN

https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js

2.2 配置

<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
<div id="main" style="width: 350px;height:250px;"></div>

<script type="text/javascript">
    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据
    var 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',
            smooth: true
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
</script>

option详细配置

option = {
   title: {
    text: '标题',
    subtext: '这是标题描述'
  },
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value',
    // 初始化 单位 (可以不填)
    axisLabel: {
      formatter: '{value} 万元'
    },
    // axisPointer: {
    //   snap: true
    // }
  },
  series: [
    {
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: 'line',
      smooth: true,
      // 取最大、小值
      markPoint: {
        data: [
          { type: 'max', name: 'Max' },
          { type: 'min', name: 'Min' }
        ]
      },
      // 取平均值
      markLine: {
        data: [{ type: 'average', name: 'Avg' }]
      }
    },
    {
      data: [10, 92, 901, 34, 190, 130, 130],
      type: 'line',
      smooth: true, // 平滑
      // 取最大、小值
      markPoint: {
        data: [
          { type: 'max', name: 'Max' },
          { type: 'min', name: 'Min' }
        ]
      },
      // 取平均值
      markLine: {
        data: [{ type: 'average', name: 'Avg' }]
      }
    }
  ],
  // 比例大小
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  // 比例大小 设置颜色
  color: ['red','blue'],
  // 鼠标聚焦
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross'
    }
  },
  // 保存图片
  toolbox: {
    show: true,
    feature: {
      saveAsImage: {}
    }
  },
};

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有勇气的牛排

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值