反向坐标轴
有时候做一些功能的折线图时需要使用到反向坐标轴(如排名的变化趋势)就需要用到Echarts的反向坐标轴的功能。
yAxis: {
type: 'value',
inverse: true, //y轴坐标轴向下
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
},
隐藏图表标题
可以使用如下代码或者直接删除这一条代码
title: {
title: { text: null },
},
tooltip内容文字的样式设置
这里参考了一位博主的博客:echarts图中tooltip内容文字的样式设置
默认的tooltip就是一个div,直接在formatter里面添加span设置好颜色就可以了
tooltip: {
backgroundColor: "#FFF", //设置tooltip的背景颜色颜色为白色(默认的为半透明黑色)
borderColor: "#C3CBD6", //修改边框线颜色(默认没有边框线颜色)
borderWidth: 1,//修改边框线的宽度
//axisPointer: { lineStyle: { color: "#C3CBD6" } },
//formatter: '<span style="color: #657180; margin-left: 8px; float: right;">{a} <br/>{b} : {c}</span>' //内容显示格式
textStyle: {//显示的字体颜色,样式以及大小
fontSize: 12,
color: '#657180',
fontFamily: 'MaerskText-Regular'
},
},
修改后的tooltip的样式
使用formatter改变数据显示方式(如添加百分号符号)
, formatter(params) {
for (x in params) {
return params[x].name + ":<br/>" + params[x].value+"%";
}
}
雷达图
radar: {
//shape: 'circle', //可以改变为圆弧形,默认是五角形
name: {
textStyle: {
padding: [7, 7],//五个角的类别名离图形的上下左右距离
color: '#2b425b',
fontSize: 14,
fontFamily: 'MaerskHeadline-Bold',
},
},//指示文字的样式
indicator: nums,
},
series: [{
symbolSize: 18, //五个角的圆圈大小
name: 'Personal competence',
type: 'radar',
itemStyle: {
normal: {
color: 'red', //数值显示的颜色
lineStyle: {
color: '#29a4ff' //内部边框线的颜色,这里改为了蓝色
}
}
},
areaStyle: { normal: { color: '#ffffff' } },//内部区域图形的颜色
data: [
{
value: values,
label: {
normal: {
show: true,
formatter: function (params) {
return params.value
}
}
}//折线上显示具体数值
}
]
}]
柱形图(单一种类)
myChart.setOption(option);
option_Bar = {
tooltip: {
backgroundColor: "#FFF",
borderColor: "#C3CBD6",
borderWidth: 1,
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
textStyle: {
fontSize: 12,
color: '#657180',
fontFamily: 'MaerskText-Regular'
},
},//tooltip的样式设置
calculable: true,
xAxis: [
{
type: 'category',
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
data: nums_Bar,
}
],//x轴的样式和数值
yAxis: [
{
type: 'value',
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
}
],//y轴的样式和数值
series: [
{
barWidth: '20',
name: 'Volume',
type: 'bar',
data: values_Bar,
itemStyle: {
normal: {
color: '#43afd4', //柱形图的颜色设置,这里为蓝色
label: {
show: true,//是否在柱形图上显示数值
position: 'top',//设置柱形图数值显示的位置,这里设置在柱形图的顶部
formatter: '{c}',//柱形图数值的的格式,这里只让它显示了数值,当然也可以显示类名等等
fontFamily: 'MaerskText-Regular',//数值显示的字体样式
fontSize: 12,//数值显示的的字体大小
}
},
},
},
]
};
myChart_Bar.setOption(option_Bar);
柱状图(多种类)
与只有一个种类的柱形图相比,多种类的需要再series中添加更多的数据源
var myChart = echarts.init(document.getElementById('Bar'));
option = {
title: {
text: 'TOP 10 IN THE TEAM',
textStyle: {
fontSize: 16,
fontFamily: 'MaerskHeadline-Regular',
}
},
color: ['#43afd4', '#13253b', '#878787'],//柱形图的颜色
tooltip: {
backgroundColor: "#FFF",
borderColor: "#C3CBD6",
borderWidth: 1,
trigger: 'axis',
formatter: function (params) {
var res = '<div><p>' + params[0].name + '</p></div>'
for (var i = 0; i < params.length; i++) {
if (i==2) {
res += '<p>' + params[i].seriesName + ':' + params[i].data + '%</p>'
} else {
res += '<p>' + params[i].seriesName + ':' + params[i].data + '</p>'
}
}
return res;
},
textStyle: {
fontSize: 12,
color: '#657180',
fontFamily: 'MaerskText-Regular'
},
},
legend: {
y: '0px',
data: ['Total Score', 'Accuracy', 'Production']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
saveAsImage: { show: true }
}
},
calculable: true,
xAxis: [
{
type: 'category',
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
data: names,
}
],
yAxis: [
{
type: 'value',
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
}
],
series: [
{
barWidth: '15',
name: 'Total Score',
type: 'bar',
barGap: 0,
data: AVGScore,
itemStyle: {
normal: {
label: {
show: true,
position: 'top',
formatter: '{c}',
fontFamily: 'MaerskText-Regular',
}
},
},
},
{
barWidth: '15',
name: 'Accuracy',
type: 'bar',
data: AVGAcc,
itemStyle: {
normal: {
label: {
show: true,
position: 'top',
formatter: '{c}',
fontFamily: 'MaerskText-Regular',
}
},
},
},
{
barWidth: '15',
name: 'Production',
type: 'bar',
data: AVGPro,
itemStyle: {
normal: {
label: {
show: true,
position: 'top',
formatter: '{c}%',
fontFamily: 'MaerskText-Regular',
}
},
},
},
]
};
myChart.setOption(option);
折线图(单一种类折现趋势)
option_RankLine = {
tooltip: {
backgroundColor: "#FFF",
borderColor: "#C3CBD6",
borderWidth: 1,
textStyle: {
fontSize: 12,
color: '#657180',
fontFamily: 'MaerskText-Regular'
},
trigger: 'axis'
},
toolbox: {
show: true,
orient: 'vertical',
left: 'right',//显示在图形的最右边
top: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },//数据视图,即以表格的方式显示折线的数据
magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },//切换为折线图,柱形图,堆叠图按钮
restore: { show: true },//充型加载数据按钮
saveAsImage: { show: true }//下载图片按钮
}
},//侧边的工具栏
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},//图形到容器div的距离
xAxis: {
type: 'category',
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
boundaryGap: false,
data: rank_weeknum,
},
yAxis: {
type: 'value',
inverse: true,//反向y轴
axisLabel: {
show: true,
textStyle: {
fontFamily: 'MaerskText-Regular',
}
},
},
series: [
{
name: 'Rank',
type: 'line',
data: rank_num,
itemStyle: {
normal: {
color: '#43afd4',
label: {
show: true,
position: 'top',
formatter: '{c}',
fontFamily: 'MaerskText-Regular',
}
},
},
},
]
};
myChart_RankLine.setOption(option_RankLine);
折线图(多种类)
多种类折线图和单一折线图和多种类的折线图的区别是series中的数据类别更多,折线就会出现多条折线
myChart_Line.setOption({
title: {
text: 'Historical case data',
textStyle: {
fontSize: 16,
fontFamily: 'MaerskHeadline-Regular',
}
},
tooltip: {
backgroundColor: "#FFF",
borderColor: "#C3CBD6",
borderWidth: 1,
textStyle: {
fontSize: 12,
color: '#657180',
fontFamily: 'MaerskText-Regular'
},
trigger: 'axis'
},
color: ['#878787', '#00786b', '#f46a55', '#cecece', '#13253b', '#43afd4'],//设置各类别折线的颜色
legend: {
data: ["AMD booking", "Case", "Doc", "Fresh booking", "Report", "VAS report"]
},//显示在顶部的类别提示
toolbox: {
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
//magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
//restore: { show: true },
saveAsImage: { show: true }
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: names_date
},
yAxis: {
type: 'value'
},
series: [
{
name: 'AMD booking',
type: 'line',
stack: '总量',
data: nums_All_AMD_booking
},
{
name: 'Case',
type: 'line',
stack: '总量',
data: nums_All_case
},
{
name: 'Doc',
type: 'line',
stack: '总量',
data: nums_All_Doc
},
{
name: 'Fresh booking',
type: 'line',
stack: '总量',
data: nums_All_Fresh_booking
},
{
name: 'Report',
type: 'line',
stack: '总量',
data: nums_All_Report
},
{
name: 'VAS report',
type: 'line',
stack: '总量',
data: nums_All_VAS_report
}
]
});