[学习笔记] Echarts入门笔记(二)

Echarts 实践

一、demos试水
1.仿官网demo —— 柱状图

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First ECharts</title>
  <script src="js/echarts47.min.js"></script>
</head>
<body>
  <!-- 给图表准备一个具有宽高的容器(Dom) -->
  <div id="mainBox" style="width: 600px;height:400px;"></div>

  <!-- 编写相关js,配置echarts -->
  <script type="text/javascript">
    // 绑定dom;初始化echarts示例...
    var myChart = echarts.init(document.getElementById('mainBox'));

    // 指定图表的配置项和数据
    var option = {
      // 全图默认背景
      backgroundColor: 'rgba(0,0,0,0)',
      // 默认色板
      color: ['#ff7f50','#87cefa','#da70d6','#32cd32','#6495ed',
              '#ff69b4','#ba55d3','#cd5c5c','#ffa500','#40e0d0',
              '#1e90ff','#ff6347','#7b68ee','#00fa9a','#ffd700',
              '#6699FF','#ff6666','#3cb371','#b8860b','#30e0e0'],

      // 配置标题
      title: {
        x: 'center',
        y: 'top',
        text: '第一个 ECharts 实例',
        textStyle: {
            fontSize: 18,
            fontWeight: 'bolder',
            color: '#333'          // 主标题文字颜色
        },
      },
      // 配置提示信息
      tooltip: {
        show: true
      },
      // 图例组件展现了不同系列的标记(symbol),颜色和名字。可以通过点击图例控制哪些系列不显示。
      legend: {
        orient: 'horizontal',     // 布局方式,默认为水平布局,可选为:'horizontal' ¦ 'vertical'
        x: 'right',               // 水平安放位置,默认为全图居中,可选为:
                                  // 'center' ¦ 'left' ¦ 'right'
                                  // ¦ {number}(x坐标,单位px)
        y: 'top',                 // 垂直安放位置,默认为全图顶端,可选为:
                                  // 'top' ¦ 'bottom' ¦ 'center'
                                  // ¦ {number}(y坐标,单位px)
        data: [{
          name: '播放数',
          // 强制设置图形为圆
          icon: 'circle',
          // 设置文本颜色-黑色
          textStyle: {
            color: '#000'
          }
        }],

      },
      xAxis: {
        data: ['伤感','酸欠','致郁','治愈','励志','热血']
      },
      yAxis: {},
      series: [{
        name: '播放数', //系列名称
        type: 'bar', //系列图表类型
        data: [32,20,15,25,20,12] //数据内容
      }]
    };

    // 使用以上配置和数据显示图表
    myChart.setOption(option);
  </script>
</body>
</html>
  • 展示效果:
    仿官网demo-简单柱状图
    2.饼状图demo
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>饼状图demo</title>
  <script src="../js/echarts47.min.js"></script>
</head>
<body>
  <div id="mainBox" style="width: 600px;height: 400px;"></div>
  <script type="text/javascript">
    var myEcharts = echarts.init(document.getElementById('mainBox'));

    var pieOption = {
      // 全图默认背景
      // backgroundColor: 'rgba(0,0,0,0)',
      // 默认色板
      color: ['#ff7f50','#87cefa','#da70d6','#32cd32','#6495ed',
              '#ff69b4','#ba55d3','#cd5c5c','#ffa500','#40e0d0',
              '#1e90ff','#ff6347','#7b68ee','#00fa9a','#ffd700',
              '#6699FF','#ff6666','#3cb371','#b8860b','#30e0e0'],

      // 配置标题
      title: {
        x: 'left',
        y: 'top',
        text: '饼状图 ECharts 实例',
        textStyle: {
            fontSize: 18,
            fontWeight: 'bolder',
            color: '#333'          // 主标题文字颜色
        },
      },

      // 数据
      series : {
        name: '访问来源',
        type: 'pie',
        radius: '55%',  // 饼图的半径,外半径为可视区尺寸(容器高宽中较小一项)的 55% 长度。
        // roseType: 'angle',  // 把饼图显示成南丁格尔图
        data:[
          {value:235, name:'视频广告'},
          {value:274, name:'联盟广告'},
          {value:310, name:'邮件营销'},
          {value:335, name:'直接访问'},
          {value:400, name:'搜索引擎'}
        ],
        itemStyle: {
          // 阴影的配置
          emphasis: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
          },
          // 条目展示数据样式
          normal:{ 
              label: {
                  show: true, 
                  formatter: '{b} ({d}%)' //显示百分比
              }, 
              labelLine: {show:true} 
          } 
        }
      },

      // 配置提示信息
      tooltip: {
        trigger: "item",
        formatter: "{b}产值<br>{c}"
        // show: true
      }
    }

    myEcharts.setOption(pieOption);
  </script>
</body>
</html>
  • 展示效果
    echarts实例demo-饼状图
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值