Search code examples
lightningchart

Arction lighningchart js saveToFile


When I call the screenShot function I get an error

t.captureFrame is not a function

I know that the function header contains a engine: PublicEngine paramter but am I really supposed to pass that in?

the usage example seems to leave that part out e.g.

// Download 'screenshot.png'
saveToFile('screenshot')
// Attempt download 'maybeNotSupported.bmp'
saveToFile('maybeNotSupported', 'image/bmp')
// Attempt download jpeg.file with specified compression quality
saveToFile('fileName', 'image/jpeg', 0.50)

My function looks like this: (I am however making use of a wrapper function that calls screenShot and I tested that it gets to the saveToFile method.)

export function screenShot(fileName) {
    const lcjs = require('@arction/lcjs');
    const {
        saveToFile
    } = lcjs
    saveToFile(fileName, 'image/bmp');
}

Solution

  • There are two ways to use the saveToFile functionality.

    The first way is the way you have tried to use, by using the saveToFile function. When using this function the PublicEngine parameter is required as it specifies which chart instance to save. All charts that can be saved to file have engine as a property so you can pass that from the chart you have created to save it to file.

    import { lightningChart, saveToFile } from '@arction/lcjs'
    const chart = lightningChart().ChartXY()
    saveToFile(chart.engine, 'Screenshot')
    

    The other option, that can be nicer to use, is to use saveToFile method that exists in all charts that can be saved to file.

    import { lightningChart } from '@arction/lcjs'
    const chart = lightningChart().ChartXY()
    chart.saveToFile('Screenshot')
    

    the usage example seems to leave that part out e.g.

    Looks like our documentation is incorrect for this method. This will be fixed in the next release.

    Disclosure: I work as a developer for LightningChart JS.