Можно ли скрыть ось вместе с серией в общей диаграмме осей? - PullRequest
0 голосов
/ 23 октября 2019

Я использую 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
})

1 Ответ

2 голосов
/ 28 октября 2019

Да, это возможно.

При создании записей в 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 , чтобы скрыть соответствующую ось:

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

Однако вы не должны утилизировать Оси по умолчанию таким образом, так как нет никакой гарантии, что у вас будут другие Оси на своем месте при их утилизации.

...