From f1107b11af162bbf2b3a4af723efc2229d01387d Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Thu, 18 Aug 2016 10:39:00 +0200 Subject: [PATCH] add source_index to targets this is very useful in callbacks so you can access source data and use those in the callbacks Fixes #1809 --- src/data.convert.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/data.convert.js b/src/data.convert.js index 8c523f5..090041c 100644 --- a/src/data.convert.js +++ b/src/data.convert.js @@ -189,7 +189,14 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { // finish targets targets.forEach(function (t) { - var i; + var i = 0; + // index values by index in input data, e.g. json + // this is very useful in callbacks so you can access source data + // and use those in the callbacks + t.values.forEach(function (v) { + v.source_index = i++; + }); + // sort values by its x if (config.data_xSort) { t.values = t.values.sort(function (v1, v2) {