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

问题描述 投票:0回答:1

我正在使用LightningChartJS创建图表。在图例框中单击系列说明时,系列消失,但轴保持不变。是否可以将轴与系列一起隐藏?

我的轴和系列如下:-

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
})
javascript charts axis lineseries lightningchart
1个回答
0
投票

是,有可能。

在创建图例框的条目时

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()
  }
})

但是,您不应该以这种方式处理默认轴,因为不能保证在处理它时会放置其他任何轴。

© www.soinside.com 2019 - 2024. All rights reserved.