Object that is used to store, manage and modify an XY data set. Can be visualized with PointLineAreaSeries.

 // Example, create a data set object.
const dataSet = new DataSetXY({ dataPattern: 'ProgressiveX' })
PointLineAreaSeries.setDataSet(dataSet)
dataSet.appendSamples({
xValues: [0, 1, 2],
yValues: [0, 1, 2],
})

Alternatively, creating a PointLineAreaSeries will automatically create a data set, and it directly exposes all the same methods of a DataSetXY, so you can also do this for convenience:

 // Example, use data set created by series.
const series = ChartXY.addPointLineAreaSeries({ dataPattern: 'ProgressiveX' })
.appendSamples({
xValues: [0, 1, 2],
yValues: [0, 1, 2],
})

Some properties of DataSetXY can only be configured when it is created. See DataSetXYOptions for more details.

List of frequently needed methods:

Hierarchy

  • DataSetXY

Implements

Constructors

Methods

  • Deprecated

    Use appendJSON instead

    Parameters

    • data: {
          x: number;
          y: number;
      }[] | {
          x: number;
          y: number;
      }

    Returns DataSetXY

  • 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. 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, {
    xValues: [0],
    yValues: [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, {
    xValues: [0, 1, 2],
    yValues: [10, 11, 12]
    })
     // Example, alter last sample to have Y = 0.
    DataSetXY.alterSamples(DataSetXY.getNextSampleIndex() - 1, {
    yValues: [0]
    })

    See also alterSamplesByID.

    Returns

    Object itself.

    Parameters

    • iSampleMin: number

      First altered sample index.

    • values: {
          colors?: number[] | Uint32Array | Color[];
          count?: number;
          ids?: number[] | Uint32Array;
          lookupValues?: number[] | Float32Array;
          offset?: number;
          offsetColors?: number;
          offsetIds?: number;
          offsetLookupValues?: number;
          offsetRotations?: number;
          offsetSizes?: number;
          rotations?: number[] | Float32Array;
          sizes?: number[] | Float32Array;
          x?: number;
          xValues?: number[] | TypedArray;
          y?: number;
          yValues?: number[] | TypedArray;
      }

      Object with new sample values. Behaves same as appendSamples.

      • Optional colors?: number[] | Uint32Array | Color[]
      • Optional count?: number
      • Optional ids?: number[] | Uint32Array
      • Optional lookupValues?: number[] | Float32Array
      • Optional offset?: number
      • Optional offsetColors?: number
      • Optional offsetIds?: number
      • Optional offsetLookupValues?: number
      • Optional offsetRotations?: number
      • Optional offsetSizes?: number
      • Optional rotations?: number[] | Float32Array
      • Optional sizes?: number[] | Float32Array
      • Optional x?: number
      • Optional xValues?: number[] | TypedArray
      • Optional y?: number
      • Optional yValues?: number[] | TypedArray

    Returns DataSetXY

  • Alter existing samples in the data set.

    This method alters existing samples by referencing their ID properties. The ID property is an optional sample number property, which CAN be specified by the user. They have to be enabled using ids and afterwards can be added alongside other data properties, like x, y, etc.

     // Example, basic usage
    const dataSet = new DataSetXY({ ids: true })
    dataSet.appendSamples({
    ids: [0, 1, 2],
    yValues: [10, 12, 7],
    })
    dataSet.alterSamplesByID([1], {
    yValues: [20]
    })
    // result yValues = [10, 20, 7]
     // Example, apply same value to all altered samples
    dataSet.alterSamplesByID([0, 1, 2], { size: 5 })

    See also alterSamples.

    Returns

    Object itself.

    Parameters

    • ids: number[] | Uint32Array

      List of sample IDs that are altered.

    • values: {
          color?: number | Color;
          colors?: number[] | Uint32Array | Color[];
          lookupValue?: number;
          lookupValues?: number[] | TypedArray;
          rotation?: number;
          rotations?: number[] | Float32Array;
          size?: number;
          sizes?: number[] | Float32Array;
          x?: number;
          xValues?: number[] | TypedArray;
          y?: number;
          yValues?: number[] | TypedArray;
      }

      Object with new sample values. Behaves same as appendSamples.

      • Optional color?: number | Color
      • Optional colors?: number[] | Uint32Array | Color[]
      • Optional lookupValue?: number
      • Optional lookupValues?: number[] | TypedArray
      • Optional rotation?: number
      • Optional rotations?: number[] | Float32Array
      • Optional size?: number
      • Optional sizes?: number[] | Float32Array
      • Optional x?: number
      • Optional xValues?: number[] | TypedArray
      • Optional y?: number
      • Optional yValues?: number[] | TypedArray

    Returns DataSetXY

  • Add several samples from JSON by reading values from instructed property names.

     // Example, read x + y
    const arr = [{ x: 0, y: 0 }]
    DataSetXY.appendJSON(arr, { x: 'x', y: 'y' })
     // Example, read custom property names
    const arr = [{ timestamp: 0, voltage: 0 }]
    DataSetXY.appendJSON(arr, { x: 'timestamp', y: 'voltage' })
     // Example, only Y values
    const arr = [{ price: 0 }]
    DataSetXY.appendJSON(arr, { y: 'price' })
     // Example, color values
    const arr = [{ x: 0, y: 0, color: 0xff0000ff }]
    DataSetXY.appendJSON(arr, { x: 'x', y: 'y', color: 'color' })

    Please note that before adding optional values (lookup values, ids or colors), they need to be enabled using colors or equivalent!

    Supported sample property types:

    • x: number, Date object or Date time string
    • y: number, Date object or Date time string
    • lookupValue: number
    • id: number
    • color: either Color object or number which represents a Uint32 RGBA color with Red channel being least significant byte. Note that using Color objects in large quantities should be avoided for performance reasons.

    Returns

    Object itself.

    Type Parameters

    • T extends Record<string, any>

    Parameters

    • array: T[]

      Array with JSON objects which represent samples.

    • arg: {
          color?: { [ K in string | number | symbol]: T[K] extends number | Color ? K : never }[keyof T];
          id?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T];
          lookupValue?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T];
          rotation?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T];
          size?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T];
          start?: number;
          step?: number;
          x?: { [ K in string | number | symbol]: T[K] extends string | number | Date ? K : never }[keyof T];
          y?: { [ K in string | number | symbol]: T[K] extends string | number | Date ? K : never }[keyof T];
      } = ...

      Object which informs which property names contain data. At least x or y property should always be specified.

      • Optional color?: { [ K in string | number | symbol]: T[K] extends number | Color ? K : never }[keyof T]
      • Optional id?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T]
      • Optional lookupValue?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T]
      • Optional rotation?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T]
      • Optional size?: { [ K in string | number | symbol]: T[K] extends number ? K : never }[keyof T]
      • Optional start?: number
      • Optional step?: number
      • Optional x?: { [ K in string | number | symbol]: T[K] extends string | number | Date ? K : never }[keyof T]
      • Optional y?: { [ K in string | number | symbol]: T[K] extends string | number | Date ? K : never }[keyof T]

    Returns DataSetXY

  • Add 1 sample to data set.

     // Example, basic usage
    DataSetXY.appendSample({ x: 0, y: 0 })
     // Example, only Y value with automatic X step
    DataSetXY.appendSample({ y: 0, step: 1 })
     // Example, extra properties (color)
    DataSetXY.appendSample({ x: 0, y: 0, color: 0xff0000ff })

    Please note that before adding optional values (lookup values, ids or colors), they need to be enabled using colors or equivalent!

    Supported sample property types:

    • x: number, Date object or Date time string
    • y: number, Date object or Date time string
    • lookupValue: number
    • id: number
    • size: number
    • rotation: number
    • color: either Color object or number which represents a Uint32 RGBA color with Red channel being least significant byte. Note that using Color objects in large quantities should be avoided for performance reasons.

    Returns

    Object itself.

    Parameters

    • arg: {
          color?: number | Color;
          id?: number;
          lookupValue?: number;
          rotation?: number;
          size?: number;
          step?: number;
          x?: string | number | Date;
          y?: string | number | Date;
      }

      Object any data properties (x, y, lookupValue, color, id, size, rotation).

      • Optional color?: number | Color
      • Optional id?: number
      • Optional lookupValue?: number
      • Optional rotation?: number
      • Optional size?: number
      • Optional step?: number
      • Optional x?: string | number | Date
      • Optional y?: string | number | Date

    Returns DataSetXY

  • Add a list of samples to data set.

     // Example, basic usage.
    DataSetXY.appendSamples({
    xValues: [0, 1, 2],
    yValues: [100, 101, 102],
    })
     // Example, only Y values with automatic X step
    DataSetXY.appendSamples({
    yValues: [100, 101, 102],
    start: 0,
    step: 1,
    })
     // Example, typed array input.
    DataSetXY.appendSamples({
    yValues: new Float32Array([100, 101, 102]),
    })
     // Example, extra properties (color)
    DataSetXY.appendSamples({
    xValues: [0, 1, 2],
    yValues: [100, 101, 102],
    colors: [0xff0000ff, 0xff00ff00, 0xffff0000]
    })

    Please note that before adding optional values (lookup values, ids or colors), they need to be enabled using colors or equivalent!

    Supported sample property types:

    • x: number, Date object or Date time string
    • y: number, Date object or Date time string
    • lookupValue: number
    • id: number
    • size: number
    • rotation: number
    • color: either Color object or number which represents a Uint32 RGBA color with Red channel being least significant byte. Note that using Color objects in large quantities should be avoided for performance reasons.

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

    Returns

    Object itself.

    Parameters

    • arg: {
          colors?: number[] | Uint32Array | Color[];
          count?: number;
          ids?: number[] | Uint32Array;
          lookupValues?: number[] | Float32Array;
          offset?: number;
          offsetColors?: number;
          offsetIds?: number;
          offsetLookupValues?: number;
          offsetRotations?: number;
          offsetSizes?: number;
          rotations?: number[] | Float32Array;
          sizes?: number[] | Float32Array;
          start?: number;
          step?: number;
          xValues?: string[] | number[] | TypedArray | Date[];
          yValues?: string[] | number[] | TypedArray | Date[];
      }

      Object with data properties and optional behavior configurations.

      • Optional colors?: number[] | Uint32Array | Color[]
      • Optional count?: number
      • Optional ids?: number[] | Uint32Array
      • Optional lookupValues?: number[] | Float32Array
      • Optional offset?: number
      • Optional offsetColors?: number
      • Optional offsetIds?: number
      • Optional offsetLookupValues?: number
      • Optional offsetRotations?: number
      • Optional offsetSizes?: number
      • Optional rotations?: number[] | Float32Array
      • Optional sizes?: number[] | Float32Array
      • Optional start?: number
      • Optional step?: number
      • Optional xValues?: string[] | number[] | TypedArray | Date[]
      • Optional yValues?: string[] | number[] | TypedArray | Date[]

    Returns DataSetXY

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

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

    Returns

    Object itself.

    Parameters

    • arg: {
          color?: number | Color;
          lookupValue?: number;
          rotation?: number;
          size?: number;
          x?: number;
          y?: number;
      }

      Object with data properties.

      • Optional color?: number | Color
      • Optional lookupValue?: number
      • Optional rotation?: number
      • Optional size?: number
      • Optional x?: number
      • Optional y?: number

    Returns DataSetXY

  • 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

  • Read back the current contents of the data set.

     // Read back data
    const data = DataSetXY.readBack()
    console.log(data)

    If data cleaning (max sample count) is enabled, this can result in allocating new memory (and thus be expensive). Otherwise, a very efficient operation.

    The returned values should NOT be modified.

    Optionally, you can include the flag onlyInRange to find return only samples that are in specified range. This is only supported if the data set has a "data pattern" (e.g. { dataPattern: 'ProgressiveX' }). The range is always considered to be in the same dimension as this data pattern (e.g. X Axis).

     // Example, read back data that is visible
    ChartXY.getDefaultAxisX().onIntervalChange((axis, start, end) => {
    const data = DataSetXY.readBack({ onlyInRange: { start, end } })
    console.log(data)
    })

    This operation is not "pixel perfect", meaning it can often return 1 extra sample that is not visible (the next and/or previous ones).

    Returns

    Object with lists of separate data channels, like x coordinates, y coordinates, look up values, colors, etc.

    Parameters

    • Optional arg: {
          onlyInRange?: {
              end: number;
              start: number;
          };
      }
      • Optional onlyInRange?: {
            end: number;
            start: number;
        }
        • end: number
        • start: number

    Returns {
        colors?: Uint32Array;
        iSampleFirst: number;
        ids?: Uint32Array;
        lookupValues?: Float32Array;
        rotations?: Float32Array;
        sizes?: Float32Array;
        xValues: TypedArray;
        yValues: TypedArray;
    }

    • Optional colors?: Uint32Array
    • iSampleFirst: number
    • Optional ids?: Uint32Array
    • Optional lookupValues?: Float32Array
    • Optional rotations?: Float32Array
    • Optional sizes?: Float32Array
    • xValues: TypedArray
    • yValues: TypedArray
  • 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

    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 DataSetXY

  • 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 DataSetXY

  • 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

    • arg: {
          colors?: number[] | Uint32Array | Color[];
          count?: number;
          ids?: number[] | Uint32Array;
          lookupValues?: number[] | Float32Array;
          offset?: number;
          offsetColors?: number;
          offsetIds?: number;
          offsetLookupValues?: number;
          offsetRotations?: number;
          offsetSizes?: number;
          rotations?: number[] | Float32Array;
          sizes?: number[] | Float32Array;
          start?: number;
          step?: number;
          xValues?: string[] | number[] | TypedArray | Date[];
          yValues?: string[] | number[] | TypedArray | Date[];
      }

      Object with data properties and optional behavior configurations.

      • Optional colors?: number[] | Uint32Array | Color[]
      • Optional count?: number
      • Optional ids?: number[] | Uint32Array
      • Optional lookupValues?: number[] | Float32Array
      • Optional offset?: number
      • Optional offsetColors?: number
      • Optional offsetIds?: number
      • Optional offsetLookupValues?: number
      • Optional offsetRotations?: number
      • Optional offsetSizes?: number
      • Optional rotations?: number[] | Float32Array
      • Optional sizes?: number[] | Float32Array
      • Optional start?: number
      • Optional step?: number
      • Optional xValues?: string[] | number[] | TypedArray | Date[]
      • Optional yValues?: string[] | number[] | TypedArray | Date[]

    Returns DataSetXY