Echarts的初步认识

 

1,有以下的五个步骤

  1. 引入echarts.js文件
  2. 在视图层准备一个div盒子
  3. 初始化echarts实例化对象
  4. 准备配置项
  5. 将配置项设置给echarts实例对象
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入 -->
    <script src="../lib/echarts.min.js"></script>
</head>

<body>
    <div id="main" style="width: 500px;height: 500px;"></div>
    <div id="main2" style="width: 600px;height: 600px;"></div>
    <script>
        var box = echarts.init(document.getElementById('main'))
        var box2 = echarts.init(document.getElementById('main2'))
        var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data: ['销量', '买进']
            },
            xAxis: {
                data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
            },
            yAxis: {},
            series: [
                {
                    name: '销量',                  
                    data: [5, 20, 36, 10, 10, 20],
                    type: 'bar',
                    showBackground: true,
                    backgroundStyle: {
                        color: 'rgba(220, 220, 220, 0.8)'
                    }
                }
            ]
        };
        let option2 = {
            title: {
                text: 'echarts 教育书籍详情柱状图',
                link:'https://www.baidu.com/'
            },
            tooltip: {

            },
            legend: {
                data: ['售出', '买进']
            },
            xAxis: {
                data: ['语文', '数学', '英语', '历史', '化学', '美术', '体育']
            },
            yAxis: {

            },
            series: [
                {
                    name: '售出',
                    type: 'bar',
                    data: [5, 20, 36, 10, 10, 20, 30],

                },
                {
                    name: '买进',
                    type: 'bar',
                    data: [15, 30, 39, 20, 20, 20, 10]
                }
            ]
        }
        box.setOption(option)
        box2.setOption(option2)
    </script>
</body>

</html>

2,关于代码中配置的说明

xAxis

直角坐标系 中的 x 轴, 如果 type 属性的值为 category ,那么需要配置 data 数据, 代表在 x 轴的

呈现

yAxis

直角坐标系 中的 y 轴, 如果 type 属性配置为 value , 那么无需配置 data , 此时 y 轴会自动去

series 下找数据进行图表的绘制

series

每个系列通过 type 决定自己的图表类型, data 来设置每个系列的数据

title

echart的标题(text为标题,link可以设置超链接)textStyle可以设置一些具体的样式

配置项的网站Documentation - Apache ECharts

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值