效果:
vue2写法:
<template>
<div class="perstatimg">
<div v-show="pieshow" id="myChartpie" class="myChartpie" :style="{ width: '100%', height: '500px' }" />
<div v-show="barshow" id="myChart" class="myChart" :style="{ width: '100%', height: '500px' }" />
</div>
</template>
<script>
export default {
data() {
return {
barshow: true,
pieshow: true
}
},
mounted() {
this.drawLine()
},
methods: {
// 绘制当前用户图表
drawLine() {
const newTitle = '水果数量'
// 基于准备好的dom,初始化echarts实例
const myChart = this.$echarts.init(document.getElementById('myChart'))
const myChartpie = this.$echarts.init(document.getElementById('myChartpie'))
// 绘制图表
myChart.setOption({
// title: { text: "当前用户的点击量", subtext: "纯属虚构" },
title: { text: newTitle },
tooltip: { trigger: 'axis' },
legend: {
data: ['点击量']
},
toolbox: {
show: true,
feature: {
myTool: {
show: true,
title: '切换为饼图',
icon: 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIiAKoNAOz0ST4FANipk9wXANiiHKkIAI0BAJkoRyQCQLsAYFWBUiwCwMIAoKxAIi4EwK4BgFm2MkcCgL0FAHaOWJAPQGAAgJlCLMwAIDgCAEMeE80DIEwDoDDSv+CpX3CFuEgBAMDLlc2XS9IzFLiV0Bp38vDg4iHiwmyxQmEXKRBmCeQinJebIxNI5wNMzgwAABr50cH+OD+Q5+bk4eZm52zv9MWi/mvwbyI+IfHf/ryMAgQAEE7P79pf5eXWA3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+It24vAfeAdSZeBB8DSrOK/gdpG0omIeGD7oaQF20dsnwOuAqckHbb9uu0bwM3Jv3+OX0pBEpI+A1Ztvy3ppx7f+4G9vboRcFrSWeCx7QGwIukF6KT4UESsRsQbpZT13ncA96fp8f+kaZphSmkrpXQDuNyNPzc3R1VVF0ej0TdbW1vrdV0zHo9pO09HK44kcs7PU0rHSykXSykvOC2lHAQOSlqe0LCrbSTRNA11XbO5uXne9rNSygcdqKQV4OfBYFCGwyHD4bC11K7AKSWqqiIirkfESh/0sO0fR6MR7ZoC3ANsTDslIsg5U1UVkq5MBO2Emrf9dIdNbQCft0XT4OPxWMCrwO990GcRMT+d3IvvgH3Aa9s0LcA+SY/6Pr2TUjrUHrcZQv0KrOzC7xe2lzpOc85fl1Lea/ms65qmaToxdopSSqvBJ6WUb/uW+gV4mnP+ajAYUFVVp/5Ofm0pyjkfAQ5IutCB2qaU8pGkM8DLs0zerj7XEUFEIOmKpFMRQd9SRMQd2+dsb9h+5V9cn78Bt2yvdkd4ircTts8DfwIn+/fkjDhmewSsA0v93Dwj+bik28CXtj9NKd21/RB4AsxLWgDendB0RtLZ6cZ5m11cAi5JOirpY9vvT26qAP6wvdqKMtNe/8cb9dcALJlhjczmRF8AAAAASUVORK5CYII=',
iconStyle: {
color: 'rgba(232, 17, 17, 1)'
},
onclick: function() {
const myChartline = document.getElementById('myChart')
const myChartpie2 = document.getElementById('myChartpie')
myChartline.style.display = 'none'
myChartpie2.style.display = 'block'
}
},
magicType: { type: ['bar', 'line'] },
// restore: {},
saveAsImage: {}
// dataView: {
// readOnly: false
// },
}
},
xAxis: {
type: 'category',
boundaryGap: true,
data: [],
axisLabel: {
interval: 0,
rotate: 20,
fontSize: 12,
color: 'rgba(0, 0, 0, 1)'
}
},
grid: {
bottom: '100px'
},
dataZoom: [{
realtime: true, // 拖动滚动条时是否动态的更新图表数据
height: 25, // 滚动条高度
start: 0, // 滚动条开始位置(共100等份)
end: 50 // 结束位置(共100等份)
}, {
start: 0
}],
yAxis: {
type: 'value',
axisLabel: {
formatter: '{value}'
}
},
series: [
{
name: '访问量',
type: 'bar',
data: [],
itemStyle: {
color: '#99CCFF'
}
}
]
})
myChartpie.setOption({
title: { text: newTitle },
tooltip: {
trigger: 'axis'
},
legend: {
textStyle: { // 图例文字的样式
color: '#0b2b5e',
fontSize: 32
},
data: ['点击量']
},
toolbox: {
show: true,
feature: {
myTool: {
show: true,
title: '切换为柱状图',
icon: 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIiAKoNAOz0ST4FANipk9wXANiiHKkIAI0BAJkoRyQCQLsAYFWBUiwCwMIAoKxAIi4EwK4BgFm2MkcCgL0FAHaOWJAPQGAAgJlCLMwAIDgCAEMeE80DIEwDoDDSv+CpX3CFuEgBAMDLlc2XS9IzFLiV0Bp38vDg4iHiwmyxQmEXKRBmCeQinJebIxNI5wNMzgwAABr50cH+OD+Q5+bk4eZm52zv9MWi/mvwbyI+IfHf/ryMAgQAEE7P79pf5eXWA3DHAbB1v2upWwDaVgBo3/ldM9sJoFoK0Hr5i3k4/EAenqFQyDwdHAoLC+0lYqG9MOOLPv8z4W/gi372/EAe/tt68ABxmkCZrcCjg/1xYW52rlKO58sEQjFu9+cj/seFf/2OKdHiNLFcLBWK8ViJuFAiTcd5uVKRRCHJleIS6X8y8R+W/QmTdw0ArIZPwE62B7XLbMB+7gECi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inwTVQaOMBxsqkbjHO8qChjbaxHdf5Tce5bEfR7iRvn+LjIW74bAAYXPu81BCW0AAAAAElFTkSuQmCC',
iconStyle: {
color: 'rgba(232, 17, 17, 0)'
},
onclick: function() {
const myChartline = document.getElementById('myChart')
const myChartpie2 = document.getElementById('myChartpie')
myChartline.style.display = 'block'
myChartpie2.style.display = 'none'
}
},
// restore: {},
saveAsImage: {}
}
},
series: [
{
name: '访问量',
type: 'pie',
id: 'pie',
radius: '70%',
center: ['50%', '50%'],
label: {
formatter: '{b}: {@2012} ({d}%)',
textStyle: {
fontSize: 16
}
},
data: [],
itemStyle: {
emphasis: {
hadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
},
normal: {
color: function(params) {
// 自定义颜色
var colorList = [
'#0780cf', '#765005', '#fa6d1d', '#0e2c82', '#b6b51f', '#da1f18', '#701866', '#f47a75', '#009db2', '#024b51',
'#0780cf', '#765005', '#fa6d1d', '#0e2c82', '#b6b51f', '#da1f18', '#701866', '#f47a75', '#009db2', '#024b51'
]
return colorList[params.dataIndex]
}
}
}
}
]
}
)
// 静态数据时
myChart.setOption(
(this.option = {
xAxis: {
data: ['苹果', '梨', '桃子', '橘子', '橙子', '芒果', '香蕉', '草莓', '榴莲', '西瓜']
},
series: [
{
data: ['39', '34', '29', '16', '40', '20', '20', '10', '10', '10']
}
]
})
)
myChartpie.setOption(
(this.option = {
series: [
{
data: [
{ value: '39', name: '苹果' },
{ value: '34', name: '梨' },
{ value: '29', name: '桃子' },
{ value: '16', name: '橘子' },
{ value: '40', name: '橙子' },
{ value: '20', name: '芒果' },
{ value: '20', name: '香蕉' },
{ value: '10', name: '草莓' },
{ value: '10', name: '榴莲' },
{ value: '10', name: '西瓜' }]
}
]
})
)
// 请求数据时
// this.$axios.post("axiosurl", {"startDate": "", "endDate": ""}).then((res) => {
// this.resData = res.data;
// let PersonalAppName = new Array()
// let PersonalCount = new Array()
// let NewPersonalAppName = ""
// let NewPersonalCount = ""
// let NewPersonal = new Array();
// for (let i = 0; i < this.resData.length; i++) {
// PersonalAppName[i] = this.resData[i].name;
// NewPersonalAppName = this.resData[i].name;
// PersonalCount[i] = this.resData[i].count;
// NewPersonalCount = this.resData[i].count;
// NewPersonal[i] = {value: NewPersonalCount, name: NewPersonalname}
// }
// for (let i = 0; i < this.resData.length; i++) {
// PersonalAppName[i] = this.resData[i].name
// PersonalCount[i] = this.resData[i].count
// }
// if (PersonalAppName.length <= 0 || PersonalCount.length <= 0){
// // this.$message("暂无数据!!!");
// this.haveData = false;
// this.noData = true;
// return;
// } else {
// this.haveData = true;
// this.noData = false;
// }
// myChart.setOption(
// (this.option = {
// xAxis: {
// data: PersonalAppName,
// },
// series: [
// {
// data: PersonalCount,
// }
// ]
// })
// );
// myChartpie.setOption(
// (this.option = {
// series: [
// {
// data: NewPersonal
// }
// ]
// })
// );
// })
}
}
}
</script>
<style>
.perstatimg{
margin-top:20px;
height: 500px;
overflow: hidden;
}
</style>
react写法:
import React ,{Component} from "react";
import * as echarts from 'echarts';
export default class EchartsColumnar extends Component {
constructor(props){
super(props);
this.state={}
}
//方法的地方
componentDidMount() {
// const newTitle = '案件统计'
// 基于准备好的dom,初始化echarts实例
var chartDom = document.getElementById('myChart');
var chartDomPie = document.getElementById('myChartpie');
var myChart = echarts.init(chartDom);
var myChartpie = echarts.init(chartDomPie);
// 绘制图表
myChart.setOption({
// title: { text: newTitle },
tooltip: { trigger: 'axis' },
legend: {
data: ['点击量']
},
toolbox: {
show: true,
feature: {
myTool: {
show: true,
title: '切换为饼图',
icon: 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167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ASUVORK5CYII=',
iconStyle: {
color: 'rgba(232, 17, 17, 1)'
},
onclick: function() {
const myChartline = document.getElementById('myChart')
const myChartpie2 = document.getElementById('myChartpie')
myChartline.style.display = 'none'
myChartpie2.style.display = 'block'
}
},
magicType: { type: ['bar', 'line'] }
}
},
xAxis: {
type: 'category',
boundaryGap: true,
data: this.props.data.content.stdata,
axisLabel: {
interval: 0,
rotate: 20,
fontSize: 12,
color: 'rgba(0, 0, 0, 1)'
}
},
grid: {
bottom: '100px'
},
yAxis: {
type: 'value',
axisLabel: {
formatter: '{value}'
}
},
series: [
{
name: '访问量',
type: 'bar',
data: this.props.data.content.data,
itemStyle: {
color: '#99CCFF'
}
}
]
})
myChartpie.setOption({
// title: { text: newTitle },
toolbox: {
show: true,
feature: {
myTool: {
show: true,
title: '切换为柱状图',
icon: 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIiAKoNAOz0ST4FANipk9wXANiiHKkIAI0BAJkoRyQCQLsAYFWBUiwCwMIAoKxAIi4EwK4BgFm2MkcCgL0FAHaOWJAPQGAAgJlCLMwAIDgCAEMeE80DIEwDoDDSv+CpX3CFuEgBAMDLlc2XS9IzFLiV0Bp38vDg4iHiwmyxQmEXKRBmCeQinJebIxNI5wNMzgwAABr50cH+OD+Q5+bk4eZm52zv9MWi/mvwbyI+IfHf/ryMAgQAEE7P79pf5eX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U2ZaExZmNVwq3EEj6MdFSkfBlmk9hNf8B6TGsEc1/gRuFc4Tyomf51BcFLKsF2kfItTrES7QHOGlP+57QwD/EoOvDnnZf3d8nLia05JdSbBhdn/I9hPfEO0YtwKrGLeA4wT3Ev/cgevY7wRj7t45BsJ10kEBlE8Cu5VKrgXrbDzJOoOPlVkd4mHZS7Hs+gbyQ/oJVGfYinwTVQaOMBxsqkbjHO8qChjbaxHdf5Tce5bEfR7iRvn+LjIW74bAAYXPu81BCW0AAAAAElFTkSuQmCC',
iconStyle: {
color: 'rgba(232, 17, 17, 0)'
},
onclick: function() {
const myChartline = document.getElementById('myChart')
const myChartpie2 = document.getElementById('myChartpie')
myChartline.style.display = 'block'
myChartpie2.style.display = 'none'
},
}
}
},
series: [
{
type: 'pie',
id: 'pie',
radius: '40%',
center: ['50%', '40%'],
label: {
formatter: '{b}: {@2012} ({d}%)',
textStyle: {
fontSize: 10
}
},
data: this.props.data.content.data,
itemStyle: {
emphasis: {
hadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
},
normal: {
color: function(params) {
// 自定义颜色
var colorList = [
'#0780cf', '#765005', '#fa6d1d', '#0e2c82', '#b6b51f', '#da1f18', '#701866', '#f47a75', '#009db2', '#024b51',
'#0780cf', '#765005', '#fa6d1d', '#0e2c82', '#b6b51f', '#da1f18', '#701866', '#f47a75', '#009db2', '#024b51'
]
return colorList[params.dataIndex]
}
}
}
}
]
}
)
}
render(){
return(
<div>
<div style={{paddingLeft:"20px",paddingTop:"10px"}}>您好,查询到有<span className="total"> {this.props.data.content.total} </span>个案件信息。</div>
<div id="myChart" className="myChart" style={{width : "450px" , height: "300px"}} />
<div id="myChartpie" className="myChartpie" style={{width : "450px" , height: "300px",display:"none"}}/>
</div>
)
}
}