jolleekin / modern_charts

BSD 2-Clause "Simplified" License
66 stars 12 forks source link

Colors for bars within series? #3

Open rbishop-bah opened 9 years ago

rbishop-bah commented 9 years ago

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

jolleekin commented 9 years ago

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

  1. 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?

rbishop-bah commented 9 years ago

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