-
Notifications
You must be signed in to change notification settings - Fork 462
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
Displaying custom labels from an array #24
Comments
It's possible, but If you use new Chart('id', {
data: {
labels: phenoArray(historicalData).labels,
datasets: [{
label: 'Phenological States',
data: phenoArray(historicalData).values
}]
},
options: {
plugins: {
datalabels: {
formatter: function(value, context) {
return context.chart.data.labels[context.dataIndex];
}
// ... other options ...
}
}
}
} If you use formatter: function(value, context) {
return context.dataset.labels[context.dataIndex];
} |
Thank you. I have many points in my graph-is there a value that I can pass so that only some of them are labeled? Something similar to autoskip and autoskip padding with scale options? |
There isn't such feature built-in, you can make your own logic by scripting the options: {
datalabels: {
display: function(context) {
// your logic here, return true to show a label, else false to hide
// for example: display 1 label every 3 data
return context.dataIndex % 3;
}
}
} Of course it's way more complex to implement something similar to auto-skip. If you think that's a feature that makes sense, you can create a new ticket with a detailed description of the requirements and a jsfiddle that illustrates your problematic: that will help me to evaluate if we should and how to integrate that feature. Did my previous comment solve your original issue? |
The link of the sample @simonbrunel is broken :/ |
I've got an array of data points, and another one of data label strings. I'm graphing the points and would like to use the strings as labels. How do I use this plugin to do so? Here's what I've got right now:
The text was updated successfully, but these errors were encountered: