Skip to content
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

Background Color scriptable option and legend item color is black #6135

Closed
stockiNail opened this issue Mar 14, 2019 · 2 comments · Fixed by #5621
Closed

Background Color scriptable option and legend item color is black #6135

stockiNail opened this issue Mar 14, 2019 · 2 comments · Fixed by #5621
Milestone

Comments

@stockiNail
Copy link
Contributor

Expected Behavior

I used the Chart.js sample of Doughnut and I used Patternomaly to create canvas pattern. This is what I'm expecting:

correct

This is the code of scriptable options :

backgroundColor: function(context) {
	var index = context.dataIndex;
	if (index === 0){
		return pattern.draw('square', '#ff6384');
	}
	if (index === 1){
		return pattern.draw('circle', '#36a2eb');
	}
	if (index === 2){
		return pattern.draw('diamond', '#cc65fe');
	}
	if (index === 3){
		return pattern.draw('triangle', '#ffce56');
	}
	return pattern.draw('zigzag', '#fcc465');
},

Current Behavior

Using scriptable options, the result is the legend item color is black.

error

If, instead of using scriptable options, I'm passing the array of pattern, it works.

backgroundColor: [
	pattern.draw('square', '#ff6384'),
	pattern.draw('circle', '#36a2eb'),
	pattern.draw('diamond', '#cc65fe'),
	pattern.draw('triangle', '#ffce56'),
	pattern.draw('zigzag', '#fcc465')
],

I've tested also my canvas pattern (not by Patternomaly) and the result is the same.

Environment

  • Chart.js version: 2.8.0
  • Browser name and version: FF 65.0.2
@etimberg
Copy link
Member

I think this is due to #2281. The code for the legend items is

generateLabels: function(chart) {
var data = chart.data;
return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
return {
text: dataset.label,
fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
hidden: !chart.isDatasetVisible(i),
lineCap: dataset.borderCapStyle,
lineDash: dataset.borderDash,
lineDashOffset: dataset.borderDashOffset,
lineJoin: dataset.borderJoinStyle,
lineWidth: dataset.borderWidth,
strokeStyle: dataset.borderColor,
pointStyle: dataset.pointStyle,
// Below is extra data used for toggling the datasets
datasetIndex: i
};
}, this) : [];
which doesn't properly resolve scriptable options

@nagix
Copy link
Contributor

nagix commented Mar 18, 2019

#5621 addresses the issue in the legend with scriptable options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants