Interface for end user API of the LCJS engine. It provides some useful capabilities over the area enclosed by a single LCJS context (which can be just a single chart, or a Dashboard with several charts).

Commonly used properties:

  • layout: Trigger resizing of charts.
  • captureFrame: Take a screenshot of charts.
  • scale: Coordinate system that encloses entire LCJS context in pixels starting from bottom left.
  • clientLocation2Engine: Translate web page coordinate to LCJS engine coordinate.
  • engineLocation2Client: Translate LCJS engine coordinate to web page coordinate.

Hierarchy

  • PublicEngine

Properties

container: HTMLDivElement

HTML Div element that contains the rendering Engine.

restoreMouseStyle: ((key?: number) => void)

Type declaration

    • (key?: number): void
    • Restore Mouse style.

      Parameters

      • Optional key: number

        Key generated using 'setMouseStyle'

      Returns void

scale: LinearScaleXY

Coordinate system that encloses entire LCJS context in pixels starting from bottom left.

Referenced usually by chart.engine.scale.

The engine scale is used as an intermediary step when translating locations from the web page into LCJS coordinates, or vice versa.

See clientLocation2Engine for translating web page coordinate to engine.scale and engineLocation2Client for translating engine.scale coordinate to web page.

To further translate a location on engine.scale to another coordinate system, like axis, use translatePoint function.

This feature is extremely powerful since it allows combining of LCJS and HTML/CSS or any web UI framework.

setMouseStyle: ((presetName: string, existingKey?: number) => number)

Type declaration

    • (presetName: string, existingKey?: number): number
    • Set Mouse style.

      Returns

      Key that can be used to restore Mouse style

      Parameters

      • presetName: string

        Name of a Mouse preset in js.

      • Optional existingKey: number

        Key for existing request to refresh

      Returns number

Methods

  • Register a custom Icon that can be used within the engine (all charts, panels, series, etc. using the same engine).

    Note that currently the Icon concept is not widely supported, and can only be used with the DataGrid feature as cell content. In the future, Icons will be more widely utilizable, for example in Legends, Cursors and UI elements.

     // Example, load a custom icon.
    const img = new Image()
    img.src = `my-icon-url.jpg`
    const icon = chart.engine.addCustomIcon(img, {})

    Icon properties can be supplied with the optional second parameter. For all available options, see IconProperties.

     // Example, specify icon width as pixels and maintain source aspect ratio.
    const icon = chart.engine.addCustomIcon(img, { width: 32 })

    Icon properties can also be adjusted using setter methods on an existing Icon object. All setters return a new Icon object, leaving the original Icon unmodified!

     // Example, make a second Icon object by adjusting an existing one.
    const icon2 = icon.setSize(16, 24)

    When a custom icon is no longer needed, it is recommended to inform the engine by disposing the Icon:

     // Example, inform engine that an Icon is no longer needed.
    icon.dispose()

    Returns

    Icon object.

    Parameters

    Returns Icon

  • Capture state of rendering Engines canvas. Returns the captured image as a Blob-object.

    Has two optional parameters which directly reference JavaScript API HTMLCanvasElement.toDataURL:

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

    Returns

    JavaScript Blob whose 'type' depends on what was passed to 'type' parameter of this method. Defaults to image/png

    Parameters

    • Optional type: string

      A DOMString indicating the image format. The default format type is image/png.

    • Optional encoderOptions: number

      A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp. If this argument is anything else, the default value for image quality is used. The default value is 0.92. Other arguments are ignored.

    Returns Blob

  • Translates a coordinate on the web page (for example, MouseEvent.clientX, MouseEvent.clientY) that originates from browser top-left, to scale.

     // Example usage, listen to chartXY background mouse move and console the location on default axis.
    chart.onSeriesBackgroundMouseMove((_, event) => {
    // Translate mouse location to LCJS coordinate system for solving data points from series, and translating to Axes.
    const mouseLocationEngine = chart.engine.clientLocation2Engine(
    event.clientX,
    event.clientY
    );

    // Translate LCJS coordinate to default chart axes.
    const mouseLocationAxis = translatePoint(mouseLocationEngine, chart.engine.scale, { x: chart.getDefaultAxisX(), y: chart.getDefaultAxisY() })
    console.log('axis', mouseLocationAxis)
    })

    To further translate a location on engine.scale to another coordinate system, like axis, use translatePoint function.

    This feature is extremely powerful since it allows combining of LCJS and HTML/CSS or any web UI framework.

    Returns

    Respective coordinate on engine.scale

    Parameters

    • x: number

      Location of X in browser

    • y: number

      Location of Y in browser

    Returns Point

  • Translates a coordinate on engine.scale that originates from LCJS bottom-left to respective location on the web page currently.

    This coordinate can, for example, be used with absolute CSS positioning:

     // Example usage, absolute position a HTML element on a coordinate along two LCJS Axes.
    const element = document.createElement('span')
    chart.engine.container.append(element)
    element.style.position = 'absolute'
    element.style.display = 'block'
    element.innerHTML = 'hello'
    element.style.color = 'red'

    const repositionElement = () => {
    // Position HTML element with CSS by translating LCJS Axis location to web page.
    const locationAxis = { x: chart.getDefaultAxisX().getInterval().start, y: chart.getDefaultAxisY().getInterval().end }
    const locationEngine = translatePoint(locationAxis, { x: chart.getDefaultAxisX(), y: chart.getDefaultAxisY() }, chart.engine.scale)
    const locationDocument = chart.engine.engineLocation2Client(locationEngine.x, locationEngine.y)
    element.style.left = `${locationDocument.x}px`
    element.style.top = `${locationDocument.y}px`
    }

    // NOTE: Axis -> Document translation is invalid if one of many things changes:
    // 1. Axis interval, style or ticks change.
    // 2. Web page is scrolled, zoomed or resized.
    // 3. Dashboard splitter is resized.
    // In this example, the element is repositioned continuously, which might not always be for the best.
    setInterval(repositionElement)

    This feature is extremely powerful since it allows combining of LCJS and HTML/CSS or any web UI framework.

    Parameters

    • x: number

      Location of X in engine

    • y: number

      Location of Y in engine

    Returns Point

  • Get Fill Style of engine background.

    Returns

    FillStyle

    Returns FillStyle

  • Get Stroke Style of engine background.

    Returns

    LineStyle

    Returns LineStyle

  • Calculate the layout again. This should be called when the container of chart is resized.

     // Example syntax, trigger chart resize on user event.
    myResizeEventCallback(() => {
    // Trigger chart resize manually.
    chart.engine.layout()
    })

    Returns void

  • Render a frame of specific size to a ArrayBuffer.

    Mainly for Node JS usage. In browser the chart itself will not be resized correctly.

    Parameters

    • width: number

      Horizontal resolution

    • height: number

      Vertical resolution

    • Optional noFlip: boolean

      Leave the image upside down

    Returns Uint8Array

  • Set Fill Style of engine background.

    Every LCJS component has an Engine background under it. In case of Dashboard, there is only 1 shared engine background.

    Transparent chart backgrounds:

    LightningChart JS charts can be configured to be fully or partially transparent.

     // Example, partially transparent chart

    // Engine background exists under all LCJS components. In case of Dashboard, there is only 1 shared engine background.
    chart.engine.setBackgroundFillStyle(emptyFill)
    // Chart background covers every 1 chart. In case of Dashboard, every chart has its own chart background.
    chart.setBackgroundFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 100) }))
    // Some charts also have a separate series background.
    chart.setSeriesBackgroundFillStyle(new SolidFill({ color: ColorRGBA(0, 0, 0, 100) }))

    Returns

    Object itself

    Parameters

    Returns PublicEngine