-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nullPtr exception in orient() #418
Comments
OK, so what i ended up doing is basically making ALL labels come up at the same location on the chart, so not good. This is the usecase i was able to pull together to reproduce in a straightforward HTML file: <DIV id="CHART" style="position: relative; width:1000px; height:600px; border: 1px solid grey;">
<CANVAS id="CHART_CNVS" style="border: 1px solid blue;"></CANVAS>
</DIV>
<SCRIPT type="module">
import { Chart, Tooltip , registerables } from "/static/jslibs/chartjs-4.4.3/chart.min.js";
import ChartDataLabels from "/static/jslibs/chartjs-plugin-datalabels-2.2.0/chartjs-plugin-datalabels.esm.js";
Chart.register(...registerables);
Chart.register([Tooltip, ChartDataLabels]);
let config = {
type: 'pie',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
datasets: [
{ data: [10.5, 20.6, 30.7, 40.9, 50.2, 60.3, 70.4, 80.2, 90, 100, 110, 120] }
]
},
options: {
cutout: "60%"
,circumference: 180
,rotation: -90
,layout: { padding: 25 }
,plugins: {
legend: null
,datalabels: {
color:'#666'
,font: { weight: 'bold', size: 14 }
,padding: 0
,textAlign: 'center'
,labels: {
index: {
align: 'end'
,anchor: 'end'
,offset: 10
,formatter: function(value, context) {
return context.chart.data.labels[context.dataIndex];
}
}
,name: {
align: 'top'
,formatter: function(value, context) {
return value;
}
}
,value: {
align: 'middle'
,offset: 10
,formatter: function(value, context) {
return '10%';
}
}
}
}
}
}
};
let chart = new Chart(document.getElementById('CHART_CNVS'), config);
</SCRIPT> This is all the more weird since on the Sample page (https://v2_2_0--chartjs-plugin-datalabels.netlify.app/samples/charts/doughnut.html), i am getting what i want in a customized sample: {
type: 'pie',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
datasets: [{
data: [10.5, 20.6, 30.7, 40.9, 50.2, 60.3, 70.4, 80.2, 90, 100, 110, 120]
}
]
},
options: {
cutout: "60%",
circumference: 180,
rotation: -90,
padding: 20,
layout: { padding: 150 },
plugins: {
datalabels: {
// anchor: 'center',
// align:'end',
// offset: 0,
// display: 'auto',
color:'#666',
font: {
weight: 'bold'
,size:14
},
padding: 0,
textAlign: 'center',
labels: {
index: {
align: 'end',
anchor: 'end',
offset: 10,
formatter: function(value, context) {
return context.chart.data.labels[context.dataIndex];
}
}
,name: {
align: 'top',
formatter: function(value, context) {
return value;
}
}
,value: {
align: 'middle',
offset: 10,
formatter: function(value, context) {
return '10%';
}
}
}
}
}
}
} Any help would be so much appreciated. |
So, i figured out what the issue was... I minified the file chart.js and it's the cause of the failure. I tried a few different minifiers and options but no success. Is there something intrinsic to ChartJS that makes it not work when minified? |
Not sure why or how, but when i use this plugin, i get a null pointer exception when accessing 'origin' on first paint of the animation. By using the ?. operator, it works. The codebase i use is complex and i haven't had a chance to create a simple usecase and i don't quite understand the underlying logic much either.
But this bandaid works it seems 😄
The text was updated successfully, but these errors were encountered: