modern_charts icon indicating copy to clipboard operation
modern_charts copied to clipboard

Colors for bars within series?

Open rbishop-bah opened this issue 9 years ago • 2 comments

Is there a way to assign distinct colors to bars within the same series?

rbishop-bah avatar May 20 '15 14:05 rbishop-bah

The package doesn't have this feature yet. That said, I can think of two ways to enable it:

  1. Google's way: add role columns
    var data = google.visualization.arrayToDataTable([
      ['Element', 'Density', { role: 'style' }, { role: 'annotation' } ],
      ['Copper', 8.94, '#b87333', 'Cu' ],
      ['Silver', 10.49, 'silver', 'Ag' ],
      ['Gold', 19.30, 'gold', 'Au' ],
      ['Platinum', 21.45, 'color: #e5e4e2', 'Pt' ]
    ]);

https://developers.google.com/chart/interactive/docs/gallery/columnchart 2. My way: use inline objects

    var data = google.visualization.arrayToDataTable([
      ['Element', 'Density'],
      ['Copper', { 'value': 8.94, 'color': '#b87333', 'annotation': 'Cu' }],
      ['Silver', { 'value': 10.49, 'color': 'silver', 'annotation': 'Ag' }],
      ['Gold', { 'value': 19.30, 'color': 'gold', 'annotation': 'Au' }],
      ['Platinum', { 'value': 21.45, 'color': '#e5e4e2', 'annotation': 'Pt' }]
    ]);

I'm leaning toward the second option as it's more flexible. Do you have any suggestion?

jolleekin avatar May 22 '15 04:05 jolleekin

I prefer the inline maps as well as long as the supported properties are documented.

rbishop-bah avatar May 22 '15 10:05 rbishop-bah