Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

402
Views
How to use pointStyle with image in chartjs-node-canvas?

I am trying to render chart with image using pointStyle. I implemented this chart on client side and its working fine but when i try to render chart using nodejs (SSR) its show only chart without an image.

Nodejs Code

var express = require("express");
const { Canvas, loadImage } = require("canvas");
const { CanvasRenderService } = require("chartjs-node-canvas");


var router = express.Router();

async function initChartData() {
  const img = await loadImage("https://i.imgur.com/yDYW1I7.png");
  const canvas = new Canvas(img.width, img.height);
  var ctx = canvas.getContext("2d");
  ctx.drawImage(img, 0, 0, img.width, img.height);
  console.log('<img src="' + canvas.toDataURL() + '" />');

  const data = {
    labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
    datasets: [
      {
        label: "Tokyo",
        fill: false,
        borderColor: "rgba(75,192,192,1)",
        pointBackgroundColor: "#fff",
        pointRadius: 5,
        pointStyle: '<img src="' + canvas.toDataURL() + '" />', // or ['',img,'','','','']
        data: [0, 7, 8, 14, 18, 22],
      },
    ],
  };

 const configuration = {
    type: "line",
    data: data,
    options: {
      responsive: false,
      animation: false,
      maintainAspectRatio: false,
    },
  };
  return configuration;
}

const mkChart = async (params) => {
  const conf = await initChartData();
  const canvasRenderService = new CanvasRenderService(400, 400);
  return await canvasRenderService.renderToBuffer(conf);
};

router.get("/", async function (req, res, next) {
  var image = await mkChart(req.query);
  res.type("image/png");
  res.send(image);
});

module.exports = router;

Package.json

  "dependencies": {
    "canvas": "^2.8.0",
    "chart.js": "^3.5.1",
    "chartjs-node-canvas": "^3.2.0",
    "cookie-parser": "~1.4.4",
    "express": "~4.16.1",
  }

Client side demo : https://jsfiddle.net/3t1qguy7/1/ Repository https://github.com/ahmedosamaalam/node-chartjs/tree/main

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!