-
Notifications
You must be signed in to change notification settings - Fork 83
Chart does not show - Failed to execute 'arc' on 'CanvasRenderingContext2D' #9
Comments
Expanding on this- can only reproduce the problem if the chart that is to be resized has its dataset changed while it is not visible via |
This is interesting. Would you be able to set up an example where we can replicate this problem? Could potentially look at a way of catching the error? not sure if it will be possible though. Otherwise, could maybe add some way of not rendering the chart when it is hidden via Let me know if you find out any more information on this. |
|
The issue I was running into was that since the dataset was changing while Will be creating a fiddle for this when I get a chance.
|
Okay here is the fix. I was beating my head against the wall on this one as well. It was as simple as adding a try / catch. In Chart.js on line 1919 you will see the following: if (instance.options.responsive){
instance.resize(instance.render, true);
} Change it to the following: if (instance.options.responsive){
try{
instance.resize(instance.render, true);
}catch(err){
console.log(err.message);
}
} Hope this helps anyone else who is stuck and maybe it makes it into the code base. Thanks! ^_^ |
This just prevents the error from stopping further script execution. I On Fri, 7 Nov 2014 11:27 popcorn245 [email protected] wrote:
|
+1 |
+10 ... or is there a temporary workaround for this? |
Same issue with tabs in bootstrap. If the chart is in a tab that is not active at the moment the page has loaded, the chart won't display at all. I should add that this happens only for responsive charts, which makes sense since the tab is not shown at the moment. Perhaps adding an update() method to be able to manually update/redraw the chart would be a good option. |
Another bad hack or workaround for meanwhile is to check if element is hidden, e.g.: function isElementHidden(element) {
return (element.offsetParent === null);
} When element is hidden do nothing, when shown create/update chart. |
Is anyone able to create an example that causes this to happen? Would be good so we can start looking for a solution. (have a basic setup here that you can fork and edit to replicate this problem http://jsfiddle.net/ovg2jrsd/1/ ) |
Here we go: As in tricinel's comment, when the chart is located inside a container that is hidden at page load, the error is triggered and the chart is not rendered. When the container is showing and the window is resized the chart will render. Note that in this fiddle the error is not thrown, but the incorrect behaviour can still be observed. This could possibly have to do with the chart type - I previously saw the error with bar and pie chart, not line chart as in the fiddle. |
I am experiencing this problem as well. It's as simple as if you have a PIE chart and Doughnut chart and one is hidden. The error is reproduced by doing the following:
This error is also displayed every time the data is changed and one graph is hidden |
Uncaught IndexSizeError: |
Confirmed "ng-if" rather "ng-show"/"ng-hide" solves this issue and logically makes a lot of sense. |
I am getting a similar erorr Uncaught IndexSizeError in my angular implementation, the chart renders but still gives this error. Chart.min.js:10 Uncaught IndexSizeError: Failed to execute 'arc' on 'CanvasRenderingContext2D': The radius provided (-0.5) is negative. Also when the charts are hidden and then loaded, it doesn't render at all. But when i try to replicate the same, I am unable to do so here in jsfiddle. Maybe this helps someone figure out a solution. Reference Code - http://jsbin.com/ponumajuvo/1/edit |
Also noticed this in bootstrap tab control |
Facing the same error while using chart.js with ionic framework. Is any one get the solution or any type of hack? |
Try putting the chart in a |
Thanks carlcraig - even though i didnt have tabs i still went ahead and used ng-if to show the charts only if data is loaded and ng-if worked - will test it in a few more scenarios and report back. |
I have the same problem using Visual Composer (that uses Bootstrap) on Wordpress. |
@rafialikhan how did you go about it? I don't use tabs either and I am struggling to determine if data is loaded as the chart is loaded only once and only happens when I navigate through the menu. |
If have the same issue here. It even throws when the site containing the chart isn't even active. The thing is I can't reproduce it deterministically, so I guess it's some kind of race condition. Sorry I can't provide a solution for now. |
I have the same issue when resizing a reactive pie chart Options: |
same issue here, +1 |
👍 .. |
same issue here, +1 |
I don't know if it is the same issue but the chart doesn't show until I hover. |
We use a modal. With Chart.js Version 1.0.1 included it works on normal templates. When included in a modal the error in this issues title shows up. Charts don't show up at all until I hover when we use 1.0.2 like @jailandrade said. That hover issue we have since tc-angular-chartjs after version 1.0.9 or so. |
Our solution was as @mbyrne00 wrote: Change the ng-show to ng-if. The modal wasn't the problem but a parent element which had the ng-show attribute. Also downloaded Chart.js 1.0.2 today and the 'Chart just shows on hover' problem is gone. @jailandrade you should try it now. Attention: Here I could NOT get it solved with the main download link (Zip Download of Version 1.0.2) on https://github.com/nnnick/Chart.js. This one is gets the master branch as it seems. When you find commit 930b16a which is labeled as 'latest' of Version 1.0.2 on https://github.com/nnnick/Chart.js/releases THEN it works. That one has about 10 more lines of code. I didn't look up what the difference is. So anyone who has the problem, go with that commit and you should be fine. |
I am going to close this. Please re-open if the issue still happens in 2.x. |
I'm seeing this error with 3.1.1 whilst attempt to build gauges (to show disk space used): "Failed to execute 'arc' on 'CanvasRenderingContext2D': The radius provided (-2.4) is negative. |
But then with Chrome 57, I see a lot of errors with "SingleStat" when using the gauge. |
If the dataset is changed on a doughnut chart with the
responsive
option set to true, anUncaught IndexSizeError
occurs when the container is resized (when resize() is called in Chart.js).There is an issue open on the Chart.js repo: chartjs/Chart.js#592
However, the issue above states the problem happens upon resizing the initial chart. I am not experiencing the issue on the initial draw, but on subsequent chart creations. Should be able to post a sample soon, just wondering if there are any obvious answers before I get too deep into this one.
The text was updated successfully, but these errors were encountered: