3

I am initializing the chart like this

this.chart = lightningChart()
   .ChartXY({
       containerId: 'chartSection',
       theme: Themes.light
   })
  .setTitle('')

and binding the data later and would like to add defaultAxisXTickStrategy later on getting data.

Snekw
  • 2,590
  • 1
  • 15
  • 24
Learner
  • 167
  • 7

1 Answers1

4

The defaultAxisXTickStrategy can only be set when the chart is created.

I assume you would like to have axis with a tick strategy that matches the data you are getting. To achieve this you can manually create the axis with addAxisX method of the chart. This method accepts a axisTickStrategy option. Then to use this axis that was just created you would supply the created axis to a addLineSeries (or any other add...series) method options. {xAxis: createdAxis}.

// Create a new chart
const chart = lcjs.lightningChart().ChartXY({
    containerId: 'target'
  })
  .setTitle('Demo Chart')

// after 2 seconds start adding data
setTimeout(() => {
  const dateOrigin = new Date()
  // create a new axis
  const createdAxis = chart.addAxisX(
    false, lcjs.AxisTickStrategies.DateTime(dateOrigin)
  )

  // create a new series using the previously created axis for X axis
  const lineSeries = chart.addLineSeries({
    xAxis: createdAxis
  })
  // dispose the default axis from X axis
  chart.getDefaultAxisX().dispose()

  // add new data twice a second
  let i = 0
  setInterval(() => {
    lineSeries.add({
      x: 1000 * i,
      y: Math.random() * 10
    })
    i++
  }, 500)

}, 2000)
body {
  height: 100vh;
}
<script src="https://unpkg.com/@arction/lcjs@1.2.2/dist/lcjs.iife.js"></script>
<div style="height: 100%;" id="target"></div>
Snekw
  • 2,590
  • 1
  • 15
  • 24