javascript - 带有堆叠系列的 Echarts markLine
问题描述
我正在尝试使用 markLine 选项用两条线系列标记图表的顶部。这些线系列是堆叠的,但是当我尝试使用该选项type: max
进行 markLine 时,顶部图形的 markLine 显示在图形下方,因为该值低于显示的值(我附上图像以使其更清晰)。
如何将 markLine 放在图表顶部?我已经看到了这个y
参数,但我必须把它放在我认为不可能的像素中。
这是我对两个 markLines 的配置:
// First markLine
const markLineAhorro = {
data: [
{
type: 'max',
label: {
position: 'middle',
formatter: params => {
return `Sólo tienes que invertir: ${params.value.format()} €`
}
},
lineStyle: {
color: '#212529'
}
},
]
}
// Second markLine (the one on the top)
const markLineRentabilidad = {
data: [
{
type: 'max',
label: {
position: 'middle',
formatter: params => {
return `Con tu inversión obtienes: ${params.value.format()} €`
}
},
lineStyle: {
color: '#212529'
}
}
]
}
解决方案
我找到的解决方案是使用coord
参数手动将起点和终点的标记设置在我想要的位置。我使用xAxis
参数来设置markLine的起点和终点以及我要设置的最大值yAxis
。
然后我调整value
参数以显示我想要的值。
const markLineRentabilidad = {
data: [
[
{
// Use the same y coord with starting and ending point
coord: [0, patrimonioMaximo.toString()],
value: rentabilidad[rentabilidad.length - 1],
},
{
coord: [añosGrafica.length - 1, patrimonioMaximo.toString()],
}
]
]
}
推荐阅读
- php - 带有 htaccess 的 Wordpress PHP 7
- django - 如何将django rest框架中的对象转换为超链接
- pandas - 如何在熊猫中对具有不同顺序的多列进行排序?
- java - RoboVM:IDEVICE_E_NO_DEVICE
- c++ - 如何在 C/C++ 中使用 libudev 从 sys/devices 获取设备路径?
- javascript - 调试 React 上下文重新渲染
- r - 在 R 中构建直方图
- javascript - 为什么更改后对连接数组的操作会影响两个数组?
- vbscript - VBScript/ASP Classic - 解析和替换字符串中的多个项目
- typescript - 如何从枚举中获取联合类型的字符串值?