echarts使用示例

柱状图+折线图

折柱混合:https://echarts.apache.org/examples/zh/editor.html?c=mix-line-bar

在这里插入图片描述

option = {
  title:{show: true},
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      crossStyle: {
        color: '#999'
      }
    }
  },
  toolbox: {
    feature: {
      dataView: { show: true, readOnly: false },
      magicType: { show: true, type: ['line', 'bar'] },
      restore: { show: true },
      saveAsImage: { show: true }
    }
  },
  legend: {
    data: ['60周岁及以上人口', '60周岁及以上人口比重']
  },
  xAxis: [
    {
      type: 'category',
      data: ['2019', '2020', '2021', '2022', '2023'],
      axisPointer: {
        type: 'shadow'
      }
    }
  ],
  yAxis: [
    {
      type: 'value',
      name: '万人',
      min: 22000,
      max: 30000,
      interval: 1000
    },
    {
      type: 'value',
      name: '%',
      min: 12,
      max: 25,
      interval: 1,
      splitLine:false
    }
  ],
  series: [
    {
      name: '60周岁及以上人口',
      type: 'bar',
      data: [25388, 26402, 26736, 28004, 29697],
      itemStyle : { normal: {label : {show: true}}},
      barWidth: '35%',
    },
    {
      name: '60周岁及以上人口比重',
      type: 'line',
      yAxisIndex: 1,
      data: [18.1, 18.7, 18.9, 19.8, 21.1],
      itemStyle : { normal: {label : {show: true}}},
    }
  ]
};

地图

香港18区人口密度 (2011)

纯html页面可以直接导入 world.js,但是时间太久,我不记得之前在哪找的world.js了(需要修改world.js中的 echarts.registerMap(,) 地理json)

<head>
    <script src="js/echarts.min.js"></script>
    <script src="js/world.js"></script>
</head>
<body><div id="heatmap" class="charts"></div></body>

在Vue中的使用较为方便

<template>
  <div id="countryAnalysis">
    <div id="heatmap" class="charts"></div>
  </div>
</template>
<script>
import worldJson from '@/assets/world.json';

export default {
	methods: {
		handleCountry(){
			this.$echarts.registerMap("world", worldJson)
			var myChart = this.$echarts.init(document.getElementById('heatmap'));
			var option = {...}	// 去看 echarts 的地图示例的选项
    		myChart.setOption(option);
		}
	},
	mounted(){
    	this.handleCountry()
	}
}
</script>
<style>
.charts {  
    margin: 20px auto;  
    padding: 20px;  
    border: 1px solid #ccc;  
    border-radius: 5px;  
    height: 600px; width: 80%;
} 
</style>

代码中省略了

  • echarts的全局注册
  • option 选项,data 是硬编码还是从接口读取
  • 地理 JSON 数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值