简体   繁体   English

如何在 apache echarts 中正确格式化多个矩形图形?

[英]How to properly format multiple rectangle graphics in apache echarts?

I'm having trouble figuring out the best method of adding static shapes to the background of my chart using Apache Echarts.我无法找出使用 Apache Echarts 将静态形状添加到图表背景的最佳方法。 I have a graph that has multiple line series, and I'd like to provide transparent background shapes so that the viewer is able to see how the data falls into the various thresholds over time.我有一个具有多个线系列的图表,我想提供透明的背景形状,以便查看者能够看到数据如何随着时间的推移落入各种阈值。

I've figured out how to add shapes to a chart, however I'm having trouble with two things:我已经想出了如何将形状添加到图表中,但是我遇到了两件事:

  1. Forcing the shapes to fill correctly to the edge of the graph/grid area, and cut off there.强制形状正确填充到图形/网格区域的边缘,并在那里切断。
  2. Specifying exact thresholds for the shapes (from what I can tell, currently its based on pixels. I'd like to be able to drop thresholds based on y-axis values.为形状指定确切的阈值(据我所知,目前它基于像素。我希望能够根据 y 轴值降低阈值。

https://imgur.com/a/gJK91r0 https://imgur.com/a/gJK91r0

I'm at a bit of a loss for how to achieve this.我对如何实现这一目标有点茫然。 Listed below is the code I used to generate this graph.下面列出的是我用来生成此图的代码。 This is a link to the editor on apache i used, the code should be there as well.这是我使用的 apache 上的编辑器的链接,代码也应该在那里。

https://echarts.apache.org/examples/en/editor.html?c=line-simple&lang=ts&code=PYBwLglsB2AEC8sDeAoWsAeBBDEDOAXMmurGAJ4gCmRA5AMYCGYVA5sAE7m0A0J6AE2aMiAbVoBZGL1i0AKgFcqM2gHUqAlXIAWClQDEOEFQGVmphdFoBdEgF8-6cjnxFUpMpRqyAbowA2SrT2juisRgJu_LD-VABmYHQAjAAMAKS80Uas2omyqRmh6GCgRABsKUWwAEbAYCUAtuUpISThjCDaEPRi0e4entR04cAKIJkDMfF5tAUTA9m5yenzHrX1wE2wFVXFpduV0ej0Xf4CHFTQvZPo_TeD3rQX9GCrN3jaHd5397DkRAAWACsh1-pAA7hABGBtERUilQWDYNoqBAcnkAEwI3YDBxHAZ4CixKJI2BxCD-fx0DisaqMAAUlVgGKBQJ4sCZKQAdBiAJTBMF2fHoPH3H6TChDWTPV44jwfL4kpH_ZnY4UDSHQ2GwAFq0kotFLZkguWkUW_QnkYnEUnkynU2kMlls40uzk8_nqkXq82TcUDSWPGVvSYKqX-yYqxFgzUwwF6pEG9FELHRm6-95E75e0h2qnSx3053szklj0C35C-5Vga2DxCkjWUJ4KhGKiEWCiPr4oRgESdpIm5kAZiZGIxAPZGKSAA52Ulhy6kgCAOxTipN_GBuj-CDQZTRDP-3v90Twqcsqcrl0Yspz2CLyfMmdrh8pJKbiVeHd7g_1xsoHYADcQA https://echarts.apache.org/examples/en/editor.html?c=line-simple&lang=ts&code=PYBwLglsB2AEC8sDeAoWsAeBBDEDOAXMmurGAJ4gCmRA5AMYCGYVA5sAE7m0A0J6AE2aMiAbVoBZGL1i0AKgFcqM2gHUqAlXIAWClQDEOEFQGVmphdFoBdEgF8-6cjnxFUpMpRqyAbowA2SrT2juisRgJu_LD-VABmYHQAjAAMAKS80Uas2omyqRmh6GCgRABsKUWwAEbAYCUAtuUpISThjCDaEPRi0e4entR04cAKIJkDMfF5tAUTA9m5yenzHrX1wE2wFVXFpduV0ej0Xf4CHFTQvZPo_TeD3rQX9GCrN3jaHd5397DkRAAWACsh1-pAA7hABGBtERUilQWDYNoqBAcnkAEwI3YDBxHAZ4CixKJI2BxCD-fx0DisaqMAAUlVgGKBQJ4sCZKQAdBiAJTBMF2fHoPH3H6TChDWTPV44jwfL4kpH_ZnY4UDSHQ2GwAFq0kotFLZkguWkUW_QnkYnEUnkynU2kMlls40uzk8_nqkXq82TcUDSWPGVvSYKqX-yYqxFgzUwwF6pEG9FELHRm6-95E75e0h2qnSx3053szklj0C35C-5Vga2DxCkjWUJ4KhGKiEWCiPr4oRgESdpIm5kAZiZGIxAPZGKSAA52Ulhy6kgCAOxTipN_GBuj-CDQZTRDP-3v90Twqcsqcrl0Yspz2CLyfMmdrh8pJKbiVeHd7g_1xsoHYADcQA

option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
   grid: {
    left: '10%',
    right: '10%',
    top: 60,
    bottom: 60
  },
  graphic: [
    {
      type: 'group',
      left: '10%',
      right: '10%',
      bottom: 60,
      top: 60,
      children: [
        {
          type: 'rect',
          shape: {
            y: 450,
            width: 1000,
            height: 200,
          },
          style: {
            fill: 'rgba(0, 255, 0, 0.2)'
          }
        },
        {
          type: 'rect',
          shape: {
            y: 200,
            width: 400,
            height: 250,
          },
          style: {
            fill: 'rgba(255, 255, 0, 0.2)'
          }
        },
        {
          type: 'rect',
          shape: {
            y: 0,
            width: 400,
            height: 200,
          },
          style: {
            fill: 'rgba(255, 0, 0, 0.2)'
          }
        }
      ]
    }

  ],
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: 'line'
    },
    {
      data: [100, 225, 275, 268, 354, 287, 301],
      type: 'line'
    }
  ]
};

I ended up figuring out a pretty decent solution to this.我最终找到了一个相当不错的解决方案。 Adding data-less series with filled areas works pretty well and is pretty easy to implement.添加填充区域的无数据系列效果很好,并且很容易实现。

You can check out the visualization here. 你可以在这里查看可视化。

Here's the code:这是代码:

option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: 'line'
    },
    {
      data: [100, 225, 275, 268, 354, 287, 301],
      type: 'line'
    },
    {
      type: 'line',
      markArea: {
        itemStyle: {
          color: 'rgba(0, 255, 0, 0.2)'
        },
        data: [
          [
            {
              coord: [, 125]
            },
            {
              coord: [, 0]
            }
          ]
        ]
      }
    },
    {
      type: 'line',
      markArea: {
        itemStyle: {
          color: 'rgba(255, 255, 0, 0.2)'
        },
        data: [
          [
            {
              coord: [, 275]
            },
            {
              coord: [, 125]
            }
          ]
        ]
      }
    },
    {
      type: 'line',
      markArea: {
        itemStyle: {
          color: 'rgba(255, 0, 0, 0.2)'
        },
        data: [
          [
            {
              coord: [, 275]
            },
            {
              coord: [, ]
            }
          ]
        ]
      }
    }
  ]
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM