0

我正在使用 LightningChartJS 创建带有条形的图表。我有正值和负值的数据。是否有任何可用的属性,我可以根据我想看到的内容隐藏负条或正条?

注意:我显然可以编写一些基本逻辑来实现此功能,但我正在寻找一些内置功能。

const rectangles = chart.addRectangleSeries()
const addValues = (entries) => {
      for (const entry of entries) {
        bars.push(add(entry))
      }
}


const add = (entry) => {
      // Create rect dimentions.
      const rectDimensions = {
        x: x - figureThickness,
        y: 0,
        width: figureThickness,
        height: entry.value
      }
      // Add rect to the series.
      x += figureThickness + figureGap
      // Return data-structure with both original 'entry' and the rectangle figure that represents it.
      return {
        entry,
        rect
      }
    }

    chart.addValues([
  { category: '', value: 20 },
  { category: '', value: 40 },
  { category: '', value: -23 },
  { category: '', value: -29 },
  { category: '', value: 15 }
])
4

1 回答 1

2

要根据值隐藏系列/数字,您必须在应用程序端实现此逻辑。

为此,您有两种选择:

  1. 将条分成两个 RectangleSeries,一个具有正值,另一个具有负值。

  2. 像现在一样只使用一个 RectangleSeries,但单独设置每个图形的样式。当您使用 RectangleSeries.add() 添加一个矩形时,您会收到对该图的引用。

无论哪种情况,您都必须隐藏您不想看到的系列/人物并恢复您想要看到的东西。RectangleSeries 和图形都有 dispose() 和 restore() 方法。

于 2019-11-05T13:28:28.200 回答