score:8
If you use a recent Chart.JS version (2.7.1 at time of writing) you can get this running by tweaking canvas2svg a bit. I added the following code to canvas2svg: Have a look at the Codepen
ctx.prototype.getContext = function (contextId) {
if (contextId=="2d" || contextId=="2D") {
return this;
}
return null;
}
ctx.prototype.style = function () {
return this.__canvas.style
}
ctx.prototype.getAttribute = function (name) {
return this[name];
}
ctx.prototype.addEventListener = function(type, listener, eventListenerOptions) {
console.log("canvas2svg.addEventListener() not implemented.")
}
BUT: It only works if you disable animation and responsiveness of the chart (set to false).
score:0
For devices that have a devicePixelRatio different than 1 or are zoomed in/out I did:
const getDevicePixelRatio = window.devicePixelRatio
window.devicePixelRatio = 1;
// C2S Code
window.devicePixelRatio = getDevicePixelRatio
Otherwise the svg may get cropped.
score:6
In case somebody stumbles across this question, replacing the ctx in sspechts answer to C2S and disabling animation and responsiveness of the graphdata one can get the svg from the canvas. I forked the codepen project and added one function which tweaks the library with the codesnippets from sspecht and the two flags:
// deactivate responsiveness and animation
graphData.options.responsive = false;
graphData.options.animation = false;
Source: stackoverflow.com
Related Query
- Exporting chart.js charts to svg using canvas2svg.js
- How to save Chart JS charts as image without black background using blobs and filesaver?
- Merge 2 charts into 1 chart using update button (chart.js)
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Pie Chart using chart.js not showing up but bar charts are?
- Building Multiple Charts Using Chart JS in an Angular Application
- Chart changes different on zoom when using multiple charts with chart.js and flask
- Make 2 charts using chart js
- How to run Chart.js samples using source code
- how to not repeat code while creating multiple charts in chart js
- i want display chart based on selected charts using chartJS
- How to add text inside the doughnut chart using Chart.js?
- Chart Js Change Label orientation on x-Axis for Line Charts
- Converting Chart.js canvas chart to image using .toDataUrl() results in blank image
- Moving vertical line when hovering over the chart using chart.js
- create a multi line chart using Chart.js
- How to add an on click event to my Line chart using Chart.js
- Display line chart with connected dots using chartJS
- Dynamically update the options of a chart in chartjs using Javascript
- How to Draw Gantt chart using chart js or other libraries
- How to add images as labels to Canvas Charts using chart.js
- Detecting hover events over parts of a chart using Chart.js
- Overlapping Bar Chart using Chart.js
- How to add text in centre of the doughnut chart using Chart.js?
- How to create stacked bar chart using react-chartjs-2?
- How to zoom charts in chart.js using angular 7
- Display a limited number of labels only on X-Axis of Line Chart using Chart.js
- Chart.js - Add text/label to bubble chart elements without using tooltips?
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- Blank PNG image using Chart JS . toBase64Image() function
More Query from same tag
- Increase space between legend and chart
- Chart js nested pie label colors in legend
- Chart.js V2 formatting / styling labels
- chartjs angular update order
- Angular-Charts bar chart does not update when I change the data, series, labels
- generate basic pie chart using chartjs
- Chartjs v2.7 - combo chart with time-series (financial) data; bar width's are irregular
- Why is my line graph going backwards in chartjs?
- how to add a title to my ng2-charts bar chart
- chart.js one of the chart from mixed chart is not plotting
- Chart Js , repeated labels yAxis
- How to draw Horizontal line on Bar Chart Chartjs
- Chart.js2 Radar, how to configure the label padding/spacing?
- Trying to display different types of charts using select/option tag
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- Auto center ticks and values on graph when there's only one with chart.js
- Update Chart js chart dynamically in angular 2 from data getting from nodejs service
- Set Tooltip over line Chartjs
- Searchable label text Chartjs
- Unable to produce desired UI output for Chartjs tooltips
- chart.js change size of label of radar chart
- Angular + Ng2 Charts: Chart not displaying as Child Component
- Chart JS version 3 not showing in pdf for engine wkhtmltopdf
- Chart.js. Edit bar width -v2.5-
- How to unregister a chart plugin?
- Plotting objects in Chart.js
- Chart.js animation: onComplete event fired on hover
- How to hide grid lines and x-axis labels in chart.js?
- Chart.js runs in JSFiddle but not local "Chart is not defined"
- how to change the label color and set y-axis values 1k intervals and hide y-axis?