Chartjs-How to convert (convas chart) to either (Chart , or system.drawing.image , or stream , or []byte ) where I can use it in c# to generate pdf

0👍

Once you have this:

var ctx = document.getElementById("canvas_barchart");

…and you’ve then drawn your bar chart, you can do something like this:

var context = ctx.getContext('2d');
var pixels = context.getImageData(0, 0, ctx,width, ctx.height).data;

At that point you have an array of bytes representing your image. See https://www.w3schools.com/tags/canvas_getimagedata.asp to get an idea of how that byte array is structured.

Edit: This gives more detail on how the image data is structured: https://developer.mozilla.org/en-US/docs/Web/API/ImageData

Leave a comment