0

https://github.com/GraFiddle/angular-chart

In the C3 library there is a sample for data-dependent color (http://c3js.org/samples/data_color.html):

var chart = c3.generate({
    data: {
        ...,
        color: function (color, d) {
            // d will be 'id' when called for legends
            return d.id && d.id === 'data3' ? d3.rgb(color).darker(d.value / 150) : color;
        }
    }
});

So I thought I'd add a color function:

dims = {
    dt: {
      axis: 'x',
      name: 'Date',
      displayFormat: '%H:%M:%S',
      dataType: 'datetime'
    }
  };

  // key is something like errorRate etc. 
  dims[key] = {
    axis: 'y',
    name: key,
    type: 'line',
    color: function(color, d) {
      return console.log(arguments);
    }
  };

But the color function appears to be ignored. Is there a way to make a function-dependent color with this library?

jcollum
  • 43,623
  • 55
  • 191
  • 321

2 Answers2

0

Looks like its only a string, could fork it to support it and submit PR:

RE: https://github.com/GraFiddle/angular-chart/blob/master/src/js/converter.js

   // set color
    if (angular.isString(dimension.color)) {
      configuration.data.colors[key] = dimension.color;
    }         
Luke Hutton
  • 10,612
  • 6
  • 33
  • 58
0

I did manage to get it to work with angular-chart:

 # coffeescript
 graphOptions =  
   data: datapoints
   dimensions: dims
   chart:
     data:
       color: (color, d) ->
         if d.index? and data[d.index]?
           return colors[data[d.index].status]
         else return color

This function will return values from the colors hash based on the value that is in the status field of the datapoint.

jcollum
  • 43,623
  • 55
  • 191
  • 321