辅助函数不适用于为 c3.js 中的多个数据集着色

Helper function doesn't work for coloring multiple data sets in c3.js

我有以下 javascript 代码来绘制两个数据集并且每个数据集都有相同的配色方案:

here's a fiddle

var chart = c3.generate({

  data: {
    x: 'Letter',
    columns:
    [
      ['Letter', 'A','B','C','D'],
      ['test', 25,50,75,100],
      ['test2', 10, 20, 30, 40]
    ],

    type: 'bar',

    colors: {
      test: function(d) {
        return '#'+(0xff0000+(d.value-25)*256*3).toString(16);
      },
      test2: function(d) {
        return '#'+(0xff0000+(d.value-25)*256*3).toString(16);
      }
    },


  },
  axis: {
    x: {
      type: 'category'
    }
  },
  legend: {
    show: false
  }
});

但是,由于两个数据集具有相同的配色方案函数,我想将颜色函数作为它自己的辅助函数并调用它两次,如下所示:

var chart = c3.generate({

  data: {
    x: 'Letter',
    columns:
    [
      ['Letter', 'A','B','C','D'],
      ['test', 25,50,75,100],
      ['test2', 10, 20, 30, 40]
    ],

    type: 'bar',

    colors: {
      test: function(d) {
        getColor(d);
      },
      test2: function(d) {
        getColor(d);
      }
    },


  },
  axis: {
    x: {
      type: 'category'
    }
  },
  legend: {
    show: false
  }
});

function getColor(d){
    return '#'+(0xff0000+(d.value-25)*256*3).toString(16);
}

但是,as you can see with this fiddle,辅助函数不起作用,我不明白为什么。我自己添加了控制台打印语句,辅助函数确实返回了与硬编码到两个原始函数中时相同的值。

有什么非常明显的东西是我遗漏的吗?

"Is there something extremely obvious that I'm missing?"

   colors: {
      test: function(d) {
        RETURN getColor(d);
      },
      test2: function(d) {
        RETURN getColor(d);
      }
    },

我一直都是这样做的:-)