charts - 是否可以在 ECharts 中制作双栈图
问题描述
ECharts 提供堆叠选项,将多个面积/折线图堆叠在一起。
https://echarts.apache.org/en/option.html#series-line.stack
要实现它,您可以在此处粘贴以下代码:https ://echarts.apache.org/examples/en/editor.html?c=area-stack
option = {
title: {
text: 'Double stack',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985',
},
},
},
legend: {
data: ['stack 1', 'stack 2', 'basis'],
},
toolbox: {
feature: {
saveAsImage: {},
},
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
xAxis: [
{
type: 'category',
boundaryGap: false,
data: ['0', '1', '2', '3', '4', '5', '6'],
},
],
yAxis: [
{
type: 'value',
},
],
series: [
{
name: 'stack 1',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140, 150, 160, 180, 160, 240, 160],
},
{
name: 'stack 2',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120, 140, 130, 150, 120, 160, 125],
},
{
name: 'basis',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
],
};
但是,我想将绿色和红色图表都堆叠在蓝色图表上以获得如下结果:
我可以将蓝色的值添加到其他两个图表中并获得结果并获得以下选项:
option = {
title: {
text: 'Double stack',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985',
},
},
},
legend: {
data: ['stack 1', 'stack 2', 'basis'],
},
toolbox: {
feature: {
saveAsImage: {},
},
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
xAxis: [
{
type: 'category',
boundaryGap: false,
data: ['0', '1', '2', '3', '4', '5', '6'],
},
],
yAxis: [
{
type: 'value',
},
],
series: [
{
name: 'stack 1',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140 + 100, 150 + 110, 160 + 120, 180 + 130, 160 + 90, 240 + 130, 160 + 120],
},
{
name: 'stack 2',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120 + 100, 140 + 110, 130 + 120, 150 + 130, 120 + 90, 160 + 130, 125 + 120],
},
{
name: 'basis',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
],
};
但是这样我会失去 ECharts 的交互功能。
有没有可能的方法来做到这一点?要将红色和绿色图表堆叠在蓝色图表上,但不能相互堆叠?
解决方案
您需要像这样对所有系列的名称进行相同的操作。
series: [
{
name: 'stack',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140, 150, 160, 180, 160, 240, 160],
},
{
name: 'stack',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120, 140, 130, 150, 120, 160, 125],
},
{
name: 'stack',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
],
而且,您可以使用此修改工具提示
我希望,它会对你有所帮助。
推荐阅读
- excel - if 块的应用程序定义或对象定义错误
- php - 将 MongoDB 连接到项目 - 错误
- vue.js - 如何在 Vue Echarts 中创建饼图?
- swift - RxSwift 单独的流
- r - geom_beeswarm 和手动设置颜色 (scale_fill_manual)
- python - 如何在 python 代码中将一个文件夹的数据从 Blob 存储复制到另一个 Blob 存储?
- python - 在 Python 中使用 for ... in range 循环查找某个区间内的素数
- android - 在 JNI C 中检查包是否安装在 android 设备上
- vue.js - 如何在 vuex 模块中调用 vue 方法?
- node.js - Angular 8 - 从“ng serve..”获取配置参数(Ej.--configuration)