在共享轴图中,是否可以将轴与系列一起隐藏?

In shared axis chart is it possible to hide the axis along with the series?

我正在使用 LightningChartJS 创建图表。单击图例框中的系列描述,系列消失,但轴 stays.Is 是否可以将轴与系列一起隐藏?

我的坐标轴和系列如下:-

const axis1 = chart.getDefaultAxisY()
.setStrokeStyle(axisYStrokeStyles[0])
.setOverlayStyle(axisYStylesHighlight[0])
.setNibOverlayStyle(axisYStylesHighlight[0])
.setTickStyle(visibleTick => visibleTick
              .setLabelFillStyle(axisLabelStyle)
              .setGridStrokeStyle(emptyLine)
             )
const axis2 = chart.addAxisY(false)
.setTitle('No of units produced')
.setStrokeStyle(axisYStrokeStyles[1])
.setOverlayStyle(axisYStylesHighlight[1])
.setNibOverlayStyle(axisYStylesHighlight[1])
.setTickStyle(visibleTick => visibleTick
              .setLabelFillStyle(axisLabelStyle)
              .setGridStrokeStyle(emptyLine)
             )

             const splineSeries1 = chart.addSplineSeries({
  xAxis: axisX,
  yAxis: axisY1
})
const splineSeries2 = chart.addSplineSeries({
  xAxis: axisX,
  yAxis: axisY2
})

是的,有可能。

创建 LegendBox 条目时

const legendBox = chart.addLegendBox( LegendBoxBuilders.HorizontalLegendBox )
// Add a single entry to the LegendBox. Since we know there is only one Entry, we can
// cast the returned entry as one to avoid checking for Arrays.
const entry = legendBox.add( series, true, splineSeries2.getName() ) as LegendBoxEntry

可以订阅onSwitch事件隐藏对应的Axis:

// Subscribe to the onSwitch event.
entry.onSwitch( ( _, state ) => {
  // The state parameter is the state of the CheckBox
  // If the CheckBox was just switched off, dispose of the Axis. Else, restore it.
  if ( !state ) {
    AxisY2.dispose()
  } else {
    AxisY2.restore()
  }
})

但是,您不应该以这种方式处理默认的 Axes,因为不能保证在您处理它时会有任何其他 Axis 代替它。