question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One Dataset with multiple columns/rows are all same colour

See original GitHub issue

I have spotted an issue and not sure if there is a way around it.

If one dataset has multiple rows, lines, columns then the bars/lines are all coloured the same colour:

e.g.

let title = data.chartData[0].chartTitle;
let labels = data.chartData.map(a => a.title);
let values = data.chartData.map(a => a.value);
...
datasets: [{
   label: title,
   borderWidth: 1,
   data: values
},

Is there a way around this or do I need to design my charts differently or find another solution to colour the bars? I can colour them by specifying an array of background colours.

Thanks Robin

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

14reactions
kieldoylecommented, Jul 20, 2019

Based on a workaround from this reply to another issue:

https://github.com/nagix/chartjs-plugin-colorschemes/issues/7#issuecomment-476723949

It is possible to access the underlying arrays of colours in the plugin. So you can directly apply the colours to a single dataset. For example this simple bar graph has a single dataset with each bar being coloured using the ‘Tableau10’ palette.

var myChart = new Chart(document.getElementById('myChart'), {
  type: 'bar',
  data: {
    labels: ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven'],
    datasets: [{
      label: '# of things',
      data: [12, 19, 3, 5, 2, 3, 4],
      backgroundColor: Chart['colorschemes'].tableau.Tableau10,
    }]
  },
  options: {
    scales: {
      yAxes: [{
        ticks: {
          beginAtZero: true
        }
      }]
    }
  }
});

As the palettes are simple arrays of hex strings they can be manipulated and extended to suit your data.

1reaction
muniquewcommented, Jul 16, 2019

I had the same problem, but I got it working after adding

case"bar":

on the switch case, it’s now like this:

switch (o = d % l, n = t[i ? l - o - 1 : o], f[b] = {}, f.type || e.config.type) {
	case "line":
	case "radar":
	case "scatter":
		(void 0 === f.backgroundColor || s) && (f[b].backgroundColor = f.backgroundColor, f.backgroundColor = c.color(n).alpha(u).rgbString()), (void 0 === f.borderColor || s) && (f[b].borderColor = f.borderColor, f.borderColor = n), (void 0 === f.pointBackgroundColor || s) && (f[b].pointBackgroundColor = f.pointBackgroundColor, f.pointBackgroundColor = c.color(n).alpha(u).rgbString()), (void 0 === f.pointBorderColor || s) && (f[b].pointBorderColor = f.pointBorderColor, f.pointBorderColor = n);
		break;
	case "doughnut":
	case "pie":
	case "polarArea":
	case "bar":
		(void 0 === f.backgroundColor || s) && (f[b].backgroundColor = f.backgroundColor, f.backgroundColor = f.data.map(function(f, e) {
			return o = e % l, t[i ? l - o - 1 : o]
		}));
		break;
	default:
		(void 0 === f.backgroundColor || s) && (f[b].backgroundColor = f.backgroundColor, f.backgroundColor = n)
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Filter Multiple Columns by Color in Excel (2 Methods)
In this method, I will filter multiple columns by color only using the regular Filter option of excel. In the below dataset names...
Read more >
How to Compare Two Columns in Excel (for matches ...
In this tutorial, I'll show you various ways to compare two columns in Excel. The techniques shown can be used to find/highlight matches...
Read more >
Guidelines and examples for sorting and filtering data by color
This picture shows filtering and sorting based on color or icon on the Category, M/M Δ%, and Markup columns. Conditional formatting with cell...
Read more >
Excel - Find Duplicate Rows Based on Multiple Columns
Learn how to find duplicate rows across multiple columns. This tutorial covers deleting duplicates, highlighting duplicates and highlighting ...
Read more >
How to find and highlight duplicates in Excel - Ablebits
This can be a column, a row or a range of cells. ... all instances of the same item in all the columns,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found