3π
This can be done with the DataLabels Plugin.
Add the JS file to your HTML:
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.7.0"></script>
Note: be sure to add it below the Chart.js script include.
Enable the datalabels plugin and add a custom labels formatter to the options configuration object:
plugins: {
datalabels: {
formatter: function(value, context) {
if (context.dataIndex === context.dataset.data.length - 1)
{
return value.y;
}
return "";
}
},
}
- [Chartjs]-Chart JS β set start of week for x axis time series
- [Chartjs]-ChartJS β is there any way to remove blank space around pie charts?
0π
Using DataLabels Plugin, as pointed out by @chuck in one of the comments. display
is the way to go.
plugins: {
datalabels: {
display: function(value, context) {
return context.dataIndex === context.dataset.data.length - 1;
}
},
}
- [Chartjs]-Chart.js line chart is cut off at the top?
- [Chartjs]-Horizontal stacked bar chart with chart.js
-1π
To show only that last points, you could just unset the unneeded data (json array).
To do so, (dont know what kind of data source you got) loop throught the array and use
unset($my_var["key_of_value_to_delete"]);
Normal array:
delete array[0];
Best thing to do would be: Only retrieve the data you really need. Send your Server-Request in the way, you only get the results you really need.
Keywords:
Queries and filtering
Source:stackexchange.com