前言 迟来的Vue3文章,其实早在今年3月份时就把Vue3过了一遍。在去年年末又把 TypeScript 重新学了一遍,为了上 Vue3 的车,更好的开车。在上家公司4月份时,上级领导分配了一个内部的
顺晟科技
2021-07-09 10:32:10
165
背景: 这几天在做复宏汉霖的报表.用到了echarts.git到了一个新功能.三张报表.静态页面画了两天.今天来整理下学到的知识点.
echarts官网地址
里面有许许多多的图例.目前我需要用到的是饼图Pie
和柱状图Bar
.
Pie
由上图可看出实际覆盖率用的是饼图.这里用到的就是echarts
的 Pie
.
html 页面代码:
<ion-row justify-content-between >
<div no-margin style='border-bottom: none !important;'>
<span style='margin:0px 0px 10px 0px;color: #14a3d9;display: block;'>实际覆盖客户数</span>
<div style="position: relative; margin-left: 10%;">
<img src="assets/icon/actual.png" alt="" style="width: 80px;margin-left: 40%;"/>
<p class='number'>10000人</p>
</div>
</div>
<div no-margin style='border-bottom: none !important;'>
<span style='margin:0px 0px 0px -40px;color: #d98a14;display: block;'>实际覆盖率</span>
<div #chart1 style='width:100px;height:100px;' ></div>
</div>
</ion-row>
ts 页面代码:
export class VisitReportPageNew {
@ViewChild("chart1") chart1: ElementRef;
ionViewWillEnter() {
this.setChart1();
}
setChart1() {
const ec = echarts as any;
const container = this.chart1.nativeElement;
const chart = ec.init(container);
chart.setOption({
title: {
show: true,
x: "center",
y: "center",
text: 85 + "%",
itemGap: 0, // 主副标题间距
textStyle: {
fontSize: "13",
color: "#d98a14",
},
subtext: "",
subtextStyle: {
fontSize: "13",
color: "#5B697A",
fontWeight: "600",
},
},
color: ["#d98a14", "#f1dbbb"],
series: {
name: "",
type: "pie",
radius: ["72%", "82%"],
avoidLabelOverlap: true,
hoverAnimation: false,
labelLine: {
normal: {
show: false,
},
},
data: [
{ value: 85, name: "" },
{ value: 15, name: "" },
],
},
});
}
}
还有css和module.ts页面的代码关联不大我就不放了.这里主要记住的一些基本参数.series.type
: 定义图形形状series.radius
: 图形大小,个参数是外圈,第二个参数是内圈color
: 图形颜色,个参数是分布圈主要颜色,第二个参数是剩余内容颜色title.text
: 图形中间的文字title.textStyle
: 图形中间的文字的样式series.data
: 占比值Pie
上图中的拜访次数分布by拜访目的的图就是稍复杂版的饼图.
来看下代码:
html 页面代码:
<ion-card>
<div>
<div no-margin style='border-bottom: none !important;'>
<p style="font-size: 12px;color: #999999;">拜访次数分布by拜访目的</p>
<div #chart2 style='width:300px;height:300px;margin-top: 20px;'></div>
</div>
</div>
</ion-card>
ts 页面代码:
export class VisitReportPageNew {
@ViewChild("chart2") chart2: ElementRef;
ionViewWillEnter() {
this.setChart2();
}
setChart2() {
const ec = echarts as any;
const container = this.chart2.nativeElement;
const chart = ec.init(container);
chart.setOption({
tooltip: {
name: "占比",
trigger: "item",
backgroundColor: "rgba(255,255,255,0.8)",
textStyle: {
color: "black",
},
formatter: function (params) {
return (params.marker + params.name + " : " +params.value + "人" + "(" +params.percent +"次)");
},
position: [10, 10],
},
color: ["#4584DC","#14A3D9","#5FBFE4","#2FC691","#F3B73B","#F0D7A2","#DC6025",],
legend: {
show: "true",
orient: "horizontal",
x: "center",
bottom: "6%",
itemWidth: 15,
itemHeight: 15,
itemGap: 15,
data: ["拜访目的1", "拜访目的2", "拜访目的3", "拜访目的4", "拜访目的5"],
textStyle: {
color: "#535E6C",
opacity: 0.7,
},
},
// 圆心中间说明
graphic: {
elements: [{
type: "text",
style: {
text: `占比`,
fill: "#98A6B7",
fontSize: 14,
textAlign: "center",
fontWeight: 800,
},
left: "center",
top: "32%",
}],
},
series: [{
name: "",
type: "pie",
radius: ["30%", "40%"],
center: ["50%", "34%"],
avoidLabelOverlap: true,
label: {
normal: {
formatter: `{d}次`,
borderWidth: 0,
borderRadius: 4,
fontWeight: "bold",
padding: [-20, -35, 0, -25], // 外标说明位置
rich: {
a: {
// 外标底部
color: "#606C7B",
fontSize: 14, // 字大小
},
hr: {
width: "",
borderWidth: 0.5,
height: 0,
},
b: {
// 外标顶部
fontSize: 14, // 字大小
color: "#606C7B",
},
},
},
},
labelLine: {
show: true,
length: 25,
length2: 35,
},
data: [
{
value: "1",
name: "拜访目的1",
},
{
value: "2",
name: "拜访目的2",
},
{
value: "3",
name: "拜访目的3",
},
{
value: "4",
name: "拜访目的4",
},
{
value: "5",
name: "拜访目的5",
},
],
}],
});
}
}
那个代码有点点多.... 可能以后学会了熟练了代码就变得精简了...整理一下这个稍复杂的饼图学到的属性值:series.label.normal.formatter
: 饼图块延伸出来的文字说明.series.center
: 图形在所在区域的位置.Bar
上图中的机构分布by等级是用柱状图展示的
HTML 页面代码:
<ion-row>
<div no-margin style='border-bottom: none !important;'>
<span style='color: #999999;'>机构分布by等级</span>
<div #chart1 style='width:300px;min-height:200px;' ></div>
</div>
</ion-row>
ts 页面代码:
export class VisitReportPageNew {
@ViewChild("chart1") chart1: ElementRef;
ionViewWillEnter() {
this.setChart1();
}
setChart1() {
const ec = echarts as any;
const container = this.chart1.nativeElement;
const chart = ec.init(container);
chart.setOption({
xAxis:[{
type: "category",
data: ['A级', 'B级', 'C级', 'D级',],
axisTick:{
alignWithLabel:true,
},
boundaryGap:['20%', '20%']
}],
yAxis:[{
show: false,
}],
series:[{
name:'',
barWidth: 10,
data: [60, 76, 55, 19],
type: 'bar',
color: '#32a3e7',
label: {
show: true,
position: 'top',
formatter: "{c}"+"家",
color: '#000000',
}
}]
});
}
柱状图稍微简单一些.这里用到了隐藏Y轴,修改X轴刻度.增加状图文字.学到的属性值介绍:yAxis.show
: 是否展示Y轴series.barWidth
: 柱状图的粗度调整xAxis.axisTick.alignWithLabel
: 刻度展示13
2021-07
09
2021-07
09
2021-07
09
2021-07