score:1
the reason this is happening is that your canvas's parent, .library
is hidden at the time of initialization, which sets the canvas height and width to 0. see this answer canvas height/width 0
the solution is to first initialize the canvas
and then hide the .library
div
. see code below:
$(function() {
$("#hide").on("click", () => {
$(".library").toggle();
});
var linedata = {
labels: ["january", "february", "march", "april", "may", "june"],
datasets: [{
fillcolor: "rgba(172,194,132,0.4)",
strokecolor: "#acc26d",
pointcolor: "#fff",
pointstrokecolor: "#9db86d",
data: [186, 156, 251, 144, 305, 236]
}]
}
var line = document.getelementbyid('line').getcontext('2d');
new chart(line).line(linedata);
$(".library").hide();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/chart.js/1.0.2/chart.min.js'></script>
<button id="hide">hide</button>
<div class="library" id="chart">
<canvas id="line" width="600" height="400"></canvas>
</div>
Source: stackoverflow.com
Related Query
- My chart.js canvas disappears after hide() function
- Chart disappears just after finishing animation
- Resetting transform: rotate() by removing and appending canvas not showing data after appending and redrawing chart
- ChartJs (ver: 2.8.0): Custom tooltip does not hide if clicked (or mouse pointer is moved) outside the chart canvas area
- VueJS + Chartjs - Chart only renders after code change
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Converting Chart.js canvas chart to image using .toDataUrl() results in blank image
- How do you hide the title of a chart tooltip?
- Chart.js bar chart : Grid color and hide label
- Hide empty bars in Grouped Stacked Bar Chart - chart.js
- set background color to save canvas chart
- angular-chartjs line chart TypeError: t.merge is not a function
- Can Chart.js combines Line Chart and Bar Chart in one canvas
- Blank PNG image using Chart JS . toBase64Image() function
- How to hide section in a Chart.js Pie Chart
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Chart js - Get bar width after render
- (Vue, ChartJS) Create gradient background for chart from child component canvas context
- In chart.js, Is it possible to hide x-axis label/text of bar chart if accessing from mobile?
- Callback after line chart rendered
- Chart.js pie chart not showing in Google Chrome canvas
- Chart.js update function (chart,labels,data) will not update the chart
- chart js with angular2 loading dynamic data only after zoomin
- Hovering over chart.js values in Meteor onRendered function causes chart axis shift
- React chart : prevent chart's canvas scaling with height and width
- Canvas is already in use. Chart with ID '0' must be destroyed before the canvas can be reused. chat.JS
- How to hide value in Chart JS bar
- canvas fill text vanishes when hovering over chartjs pie chart
- PrimeNg bar chart how do I hide the bar labels?
- Chart js 2.x renders the canvas invisible
More Query from same tag
- Display ellipsis for null or empty values in the bar chart using Chart.js
- how to get React chartjs to resize back down with window
- Chart.js - how to disable everything on hover
- why my multiple chart.js does not work properly?
- chart.js-datalabels-plugins don't work
- Render pie chart datasets out of 100% -- Chart.JS
- drawing bar chart with chart.js jQuery
- How to change line chart data label to icon or image in chart.js
- Chart.js: trouble with resizing on window resize
- ng2-charts tooltip and legend stopped working
- angular-chart error on line chart: unable to parse color
- Alter angular js chart wrapper to support drawing custom lines
- Chartjs xAxes gridline html (html in ticks callback)
- How to hide labels by two ticks? chartjs
- Chart.js 3.x not able to display data on chart
- Can't resolve 'chart.js/auto'
- How do I create a legend for a bar chart?
- Chart.js displays bar as overflown even below the x-axis
- How can I remove two labels from my legend with an alternative to item.datasetIndex !== 1 && item.datasetIndex !== 4; ? (Charts.js)
- [MIXED CHART.JS]How do I manipulate the label of each chart's tooltips?
- How can I keep my menu from moving other elements in the page?
- How to add an on click event to my Line chart using Chart.js
- ChartJs + ie11 doesn't work
- Animation chart js (line), animate chart drawing line by line
- Multiple bubble chart datasets for chartjs
- Angular 9: Chart.js: Monochromatic(Single color with shades) doughnut chart
- Chartjs backgroundColor for line chart does not appear in Vue app
- It is possible to always show all tooltip in Chartjs 3.1
- Chart JS 2.x: How to show a tooltip in a timeline chart?
- Angular-Chart not rendering anything