Function savePlotChart

  • Saves an Observable Plot chart as an image. You must use the Plot.dot syntax and install puppeeter (npm i puppeeter).

    // The data must be an array of objects.
    const data = [{ salary: 75000, hireDate: new Date("2023-12-22") }, ...]

    // The Plot options must be wrapped into a function.
    const chart = () => Plot.plot({
    marks: [
    Plot.dot(data, {x: "hireDate", y: "salary"})
    ]
    })

    // Change the extension to .jpg to get a JPEG file.
    const path = "./my-chart.png"

    await savePlotChart(data, chart, path)

    Parameters

    • data: {
          [key: string]: unknown;
      }[]
    • makeChart: ((data) => SVGSVGElement | HTMLElement)
        • (data): SVGSVGElement | HTMLElement
        • Parameters

          • data: {
                [key: string]: unknown;
            }[]

          Returns SVGSVGElement | HTMLElement

    • path: string

    Returns Promise<void>