You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fails with
"Can't acquire context from the given item" - actual line number depends on version
Chrome 56, all extensions disabled to avoid fingerprinting issues.
With a simple component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
<ltng:require scripts="/resource/Chart" afterScriptsLoaded="{!c.getChart}"/>
</aura:component>
[note that adding an html id to the canvas does not help]
[
note that there is line a few above here that seems to show up as blank when i look at what i wrote, but should be showing the canvas tag. reproduced below with opening and closing <> left out to make it show up:
canvas aura:id="chart" height="301" width="301"></canvas
]
And controller doing:
var ctx = component.find("chart").getElement().getContext("2d");
var barChart = new Chart(ctx, {type: 'bar', data: data, options: options});
Issue seems to have appeared with #3474 as for some reason the checks fail with Salesforce.
There are 2 lines at issue in function acquireContext(item, config), with reference to 2.4:
if (item instanceof HTMLCanvasElement)
debugger:
false
fix:
if (item instanceof HTMLCanvasElement).nodeName || item.nodeName === "CANVAS")
if (context instanceof CanvasRenderingContext2D)
debugger:
false
fix:
remove this check.
With both these fixes, 2.4 renders my graph above perfectly.
I would have made a PR except that I wasn't sure how you wanted to handle (2) since you have tests using a mock that would fail. I'd use a ducktype check for some method of CanvasRenderingContext2D, but wasn't sure if that was copacetic with your overall scheme.
The text was updated successfully, but these errors were encountered:
@kadut what is Salesforce Lightning actually rendering into? It looks like it replaces all of the DOM with it's own elements that don't actually meet the spec
I am by no means a Salesforce expert, but I believe the wrapping assumption is correct due to their security model, though they claim that the result should be indistinguishable from raw DOM. Not meeting the spec seems a Salesforce deficiency, so arguably you might not want to support it and rather have me but in a request to fix to them, but this package seems pretty popular in the Salesforce world.
Closing since I don't think this is really a Chart.js error as we're only using standard JS. IMO Salesforce doesn't meet the spec and I think it's up to them to fix.
Inclusion of Chart.js as a static resource for Salesforce Lightning has been broken since 2.4. See for example http://salesforce.stackexchange.com/questions/155591/chartjs-v2-4-0-failed-to-create-chart-cant-acquire-context-from-the-given-item.
Fails with
"Can't acquire context from the given item" - actual line number depends on version
Chrome 56, all extensions disabled to avoid fingerprinting issues.
With a simple component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
<ltng:require scripts="/resource/Chart" afterScriptsLoaded="{!c.getChart}"/>
</aura:component>
[note that adding an html id to the canvas does not help]
[
note that there is line a few above here that seems to show up as blank when i look at what i wrote, but should be showing the canvas tag. reproduced below with opening and closing <> left out to make it show up:
canvas aura:id="chart" height="301" width="301"></canvas
]
And controller doing:
var ctx = component.find("chart").getElement().getContext("2d");
var barChart = new Chart(ctx, {type: 'bar', data: data, options: options});
Issue seems to have appeared with #3474 as for some reason the checks fail with Salesforce.
There are 2 lines at issue in function acquireContext(item, config), with reference to 2.4:
if (item instanceof HTMLCanvasElement)
debugger:
false
fix:
if (item instanceof HTMLCanvasElement).nodeName || item.nodeName === "CANVAS")
if (context instanceof CanvasRenderingContext2D)
debugger:
false
fix:
remove this check.
With both these fixes, 2.4 renders my graph above perfectly.
I would have made a PR except that I wasn't sure how you wanted to handle (2) since you have tests using a mock that would fail. I'd use a ducktype check for some method of CanvasRenderingContext2D, but wasn't sure if that was copacetic with your overall scheme.
The text was updated successfully, but these errors were encountered: