Hierarchy

Implemented by

Methods

  • Add callback function to be triggered when specified event is fired.

     // Example syntax
    object.addEventListener('click', (event) => {
    console.log(event)
    })

    Some classes also report extra information about the interacted object with the second parameter:

     // Most series share information about interacted data point
    series.addEventListener('click', (event, info) => {
    console.log(info)
    })

    Optional third parameter allows registering event handlers that will automatically remove themselves after first trigger:

     // Example this listener will only fire once
    object.addEventListener('click', (event) => {})

    Each class has its own list of supported events. Some events are from HTML standard (click, pointerdown, etc.), while others are own events from LightningChart JS (dispose, resize, etc.)

    To find what events are available, you can try following:

    • If your development environment has TypeScript enabled, just write addEventListener and see what possible event types the IDE suggests. These APIs are strongly typed, and even the callback event will be correctly typed.
    • Otherwise, open the class section in API documentation and check out which interface K type parameter extends.

    Type Parameters

    Parameters

    Returns void

  • Alter existing samples in the data set by identifying them with their sample index.

    This simply refers to a incrementing counter of when each sample was first introduced. For example, 0 refers to first sample that was added to data set. When data cleaning is enabled, sample indexes do NOT shift. They always point to unique samples, even if old samples are removed.

     // Example, alter by sample index
    dataSet.alterSamplesByIndex([0, 10], {
    yValues: [20, 30]
    })

    See also:

    Returns

    Object itself.

    Parameters

    • sampleIndexes: number[] | TypedArray

      Array of sample indexes to alter.

    • values: Record<string, any>

      Values that are placed into selected samples, replacing previous values. Can be arrays, or a number to use same value for all altered samples.

    Returns DataSetXYAPI

  • Alter existing samples in the data set.

    This method alters existing samples after selecting them based on:

    1. the property key (e.g. "x", "id")
    2. that properties values (e.g. x=10).
     // Example, basic usage
    const dataSet = new DataSetXY()
    dataSet.appendSamples({
    ids: [0, 1, 2],
    yValues: [10, 12, 7],
    })
    dataSet.alterSamplesByMatch("ids", [1], {
    yValues: [20]
    })
    // result yValues = [10, 20, 7]
     // Example, apply same value to all altered samples
    dataSet.alterSamplesByMatch("ids", [0, 1, 2], { size: 5 })

    See also:

    Returns

    Object itself.

    Parameters

    • matchKey: string

      Data property that is used to select samples that should be altered.

    • matchValues: string | number | number[] | TypedArray

      Array of values that are checked from matchKey data values to select samples that should be altered.

    • values: Record<string, any>

      Values that are placed into selected samples, replacing previous values. Can be arrays, or a number to use same value for all altered samples.

    Returns DataSetXYAPI

  • Alter a continuous range of existing samples in the data set. This method also supports automatically appending samples when attempting to alter samples that don't exist in data set.

    This method alters existing samples by referencing sample indexes. This simply refers to a incrementing counter of when each sample was first introduced. For example, 0 refers to first sample that was added to data set. When data cleaning is enabled, sample indexes do NOT shift. They always point to unique samples, even if old samples are removed.

     // Example, basic usage - set first sample to { x: 0, y: 0 }
    DataSetXY.alterSamples(0, {
    x: [0],
    y: [1]
    })
     // Example, alter several samples at once - set first sample to { x: 0, y: 10 }, second sample to { x: 1, y: 11 } and so on.
    DataSetXY.alterSamples(0, {
    x: [0, 1, 2],
    y: [10, 11, 12]
    })
     // Example, alter last sample to have y = 0.
    DataSetXY.alterSamples(DataSetXY.getNextSampleIndex() - 1, {
    y: [0]
    })

    See also:

    Returns

    Object itself.

    Parameters

    • iSampleMin: number

      First altered sample index.

    • samples: Record<string, any>

      Object with new sample values. Behaves same as appendSamples.

    • Optional opts: {
          count?: number;
          offset?: number;
          start?: number;
          step?: number;
      }

      Extra options. Behaves same as appendSamples.

      • Optional count?: number
      • Optional offset?: number
      • Optional start?: number
      • Optional step?: number

    Returns DataSetXYAPI

  • Add several samples by reading from an Array of JavaScript objects.

     // Example, read x + y
    const arr = [{ x: 0, y: 0 }]
    DataSetXY.appendJSON(arr)
     // Example, property names can be anything
    const arr = [{ timestamp: 0, voltage: 0 }]
    DataSetXY.appendJSON(arr)
     // Input type can also be list of tuples
    const arr = [
    [0, 100],
    [1, 110]
    ]
    DataSetXY.appendJSON(arr)

    appendJSON will by default store all supplied data properties. If you only want to load specific properties into the data set, then you should whitelist them:

    DataSetXY.appendJSON(data, { whitelist: ['index', 'value'] })
    

    Important: the supplied objects' keys refer to keys of the data sets schema. If schema is not defined, then this operation will set it according to supplied keys with default values.

    This operation will push data to a DataSetXY object (either directly or via series). By default, series will connect to data properties that seem logical. It is, however, recommended to explicitly connect X and Y (etc.) to the correct, specific data properties using data mapping:

     // Data mapping is specified on a series
    series.setDataMapping({ x: 'timestamp', y: 'voltage' })

    Supported data property types:

    • number
    • Date object
    • ISO8601 Date time string
      • "2023-09-06T14:30:00.000Z"
      • "2023-09-06"
      • "2023-09-06T14:30:00.000+02:00"
    • Color object
      • Colors can also be loaded as single number (uint32, least significant byte = red). Using Color objects in large quantities should be avoided for performance reasons.
    • If nonNumeric: true; any value (string, boolean, etc.)

    For more detailed documentation, please see Developer documentation.

    Returns

    Object itself.

    Parameters

    • array: Record<string | number, any>[]

      Array with JSON objects which represent samples.

    • Optional opts: {
          blacklist?: string[];
          start?: number;
          step?: number;
          whitelist?: string[];
      }

      Optional extra arguments.

      • Optional blacklist?: string[]
      • Optional start?: number
      • Optional step?: number
      • Optional whitelist?: string[]
    • Optional fill: Record<string, number | Color>

      Optional data values to act as "fill behavior", i.e. fill same value for all added samples during this operation.

    Returns DataSetXYAPI

  • Add 1 sample to data set.

     // Example, basic usage
    DataSetXY.appendSample({ x: 0, y: 0 })
     // Example, only 1 value
    DataSetXY.appendSample({ temperature: 0 })

    appendSample will by default store all supplied data properties. If you only want to load specific properties into the data set, then you should whitelist them:

    DataSetXY.appendSample(sample, { whitelist: ['index', 'value'] })
    

    Important: the supplied objects keys refer to keys of the data sets schema. If schema is not defined, then this operation will set it according to supplied keys with default values.

    This operation will push data to a DataSetXY object (either directly or via series). By default, series will connect to data properties that seem logical. It is, however, recommended to explicitly connect X and Y (etc.) to the correct, specific data properties using data mapping:

     // Data mapping is specified on a series
    series.setDataMapping({ x: 'index', y: 'value' })

    Supported data property types:

    • number
    • Date object
    • ISO8601 Date time string
      • "2023-09-06T14:30:00.000Z"
      • "2023-09-06"
      • "2023-09-06T14:30:00.000+02:00"
    • Color object
      • Colors can also be loaded as single number (uint32, least significant byte = red). Using Color objects in large quantities should be avoided for performance reasons.
    • If nonNumeric: true; any value (string, boolean, etc.)

    For more detailed documentation, please see Developer documentation.

    Returns

    Object itself.

    Parameters

    • sample: Record<string, any>
    • Optional opts: {
          blacklist?: string[];
          start?: number;
          step?: number;
          whitelist?: string[];
      }

      Optional extra arguments.

      • Optional blacklist?: string[]
      • Optional start?: number
      • Optional step?: number
      • Optional whitelist?: string[]

    Returns DataSetXYAPI

  • Add a list of samples to data set.

     // Example, basic usage.
    DataSetXY.appendSamples({
    xValues: [0, 1, 2],
    yValues: [100, 101, 102],
    })

    Important: the object keys ("xValues" in above example) refer to keys of the data sets schema. If schema is not defined, then this operation will set it according to supplied keys with default values.

    This operation will push data to a DataSetXY object (either directly or via series). By default, series will connect to data properties that seem logical. It is, however, recommended to explicitly connect X and Y (etc.) to the correct, specific data properties using data mapping:

     // Data mapping is specified on a series
    series.setDataMapping({ x: 'xValues', y: 'yValues' })

    More examples:

     // Example, only 1 value
    DataSetXY.appendSamples({
    temperatures: [100, 101, 102],
    })
     // Example, typed array input.
    DataSetXY.appendSamples({
    temperatures: new Float32Array([100, 101, 102]),
    })
     // Example, uint32 colors
    DataSetXY.appendSamples({
    x: [0, 1, 2],
    y: [100, 101, 102],
    colors: [0xff0000ff, 0xff00ff00, 0xffff0000]
    })

    Passing arrays or single values can be freely alternated between, as long as at least one Array-like argument is supplied. Single value means using same argument for every new sample defined in the method call.

     // Example, use same color for every sample
    DataSetXY.appendSamples({
    yValues: [0, 10, 5],
    color: ColorRGBA(255, 0, 0)
    })

    Supported data property types:

    • Typed array
    • number[]
    • Single number
    • Date[]
    • ISO8601 Date time string array
      • "2023-09-06T14:30:00.000Z"
      • "2023-09-06"
      • "2023-09-06T14:30:00.000+02:00"
    • Color object or Color[]
      • Colors can also be loaded as single number (uint32, least significant byte = red). Using Color objects in large quantities should be avoided for performance reasons.
    • If nonNumeric: true; any value (string, boolean, etc.)

    offset property can optionally be used to start reading values from middle of input array. Can be situationally useful.

    For more detailed documentation, please see Developer documentation.

    Returns

    Object itself.

    Parameters

    • samples: Record<string, any>
    • Optional opts: {
          count?: number;
          offset?: number;
          start?: number;
          step?: number;
      }

      Optional extra arguments.

      • Optional count?: number
      • Optional offset?: number
      • Optional start?: number
      • Optional step?: number

    Returns DataSetXYAPI

  • Load same value or many values to all samples that currently exist in the data set.

     // Example, set "size" of all samples to 5
    DataSetXY.fill({ size: 5 })

    Supported data property types:

    • number
    • Date object
    • ISO8601 Date time string
      • "2023-09-06T14:30:00.000Z"
      • "2023-09-06"
      • "2023-09-06T14:30:00.000+02:00"
    • Color object
      • Colors can also be loaded as single number (uint32, least significant byte = red). Using Color objects in large quantities should be avoided for performance reasons.
    • If nonNumeric: true; any value (string, boolean, etc.)

    Returns

    Object itself.

    Parameters

    • arg: Record<string, any>

      Object with data properties.

    Returns DataSetXYAPI

  • Get current configured maximum sample count. See setMaxSampleCount for more information.

    Returns

    Number of undefined.

    Returns undefined | number

  • Get next new sample index. This also counts old samples that have been dropped out by data cleaning logic.

    Returns

    Number.

    Returns number

  • Get number of samples currently existing in the data set. This does NOT count any samples that have been dropped out by data cleaning logic.

    Returns

    Number.

    Returns number

  • Remove event listener added using addEventListener. The expected argument should be the exact same callback function that was supplied using addEventListener:

     // Basic example syntax
    const listener = () => {}
    obj.addEventListener('click', listener)
    obj.removeEventListener('click', listener)
     // Basic boilerplate of custom interaction when user drags on an object
    obj.addEventListener('pointerdown', (eventDown) => {
    let prevCoord = eventDown
    const handlePointerMove: LCJSInteractionEventListener<'pointermove'> = (eventMove) => {
    const delta = { x: eventMove.clientX - prevCoord.clientX, y: eventMove.clientY - prevCoord.clientY }
    prevCoord = eventMove
    console.log(delta, eventMove.clientX, eventMove.clientY)
    }
    const handlePointerUp: LCJSInteractionEventListener<'pointerup'> = (eventUp) => {
    window.removeEventListener('pointermove', handlePointerMove)
    window.removeEventListener('pointerup', handlePointerUp)
    }
    window.addEventListener('pointermove', handlePointerMove)
    window.addEventListener('pointerup', handlePointerUp)
    })

    Type Parameters

    Parameters

    • type: K
    • listener: ((event: DataSetXYEventMap[K], info?: unknown) => unknown)

      Listener that was added using addEventListener.

    Returns void

  • All real-time use cases (where data points are pushed in periodically) must define a "max sample count".

     // Example, keep maximum 1 million samples
    PointLineAreaSeries.setMaxSampleCount(1_000_000)

    This allocates the required amount of memory beforehand, which is crucial to get the best performance. After 1 million samples are reached, the oldest samples will start dropping out.

    Alternatively, if you are uncertain what value to use and don't want to allocate too much memory up-front, you can start small and automatically increase the buffer size as samples flow in:

     PointLineAreaSeries.setMaxSampleCount({ mode: 'auto', max: 10_000_000 })
    

    This would first allocate only small amount of memory, progressively increase memory allocation as samples come in until eventually limiting sample count to 10 million.

    Returns

    Object itself.

    Parameters

    • maxSampleCount: number

      Max sample count.

    Returns DataSetXYAPI

  • All real-time use cases (where data points are pushed in periodically) must define a "max sample count".

     // Example, keep maximum 1 million samples
    PointLineAreaSeries.setMaxSampleCount(1_000_000)

    This allocates the required amount of memory beforehand, which is crucial to get the best performance. After 1 million samples are reached, the oldest samples will start dropping out.

    Alternatively, if you are uncertain what value to use and don't want to allocate too much memory up-front, you can start small and automatically increase the buffer size as samples flow in:

     PointLineAreaSeries.setMaxSampleCount({ mode: 'auto', max: 10_000_000 })
    

    This would first allocate only small amount of memory, progressively increase memory allocation as samples come in until eventually limiting sample count to 10 million.

    Returns

    Object itself.

    Parameters

    • arg: {
          initial?: number;
          max?: number;
          mode: "auto";
      }
      • Optional initial?: number
      • Optional max?: number
      • mode: "auto"

    Returns DataSetXYAPI

  • Re-specify all values in the data set. This is a convenience method that is fundamentally equal to:

     DataSetXY.clear().appendSamples({ ... })
    

    There are currently no performance differences between using "setSamples" versus "clear + append". However, in future it is possible that setSamples can receive optimizations which would make it recommended over "clear + append". In the mean-time, setSamples is recommended for simplicity and clarity in end user applications.

    For parameters documentation, refer to appendSamples method.

    Returns

    Object itself.

    Parameters

    • samples: Record<string, any>
    • Optional opts: {
          count?: number;
          offset?: number;
          start?: number;
          step?: number;
      }
      • Optional count?: number
      • Optional offset?: number
      • Optional start?: number
      • Optional step?: number

    Returns DataSetXYAPI