diff --git a/docs/general/data-structures.md b/docs/general/data-structures.md index 37d3e63df3e..a70c2ef6a7b 100644 --- a/docs/general/data-structures.md +++ b/docs/general/data-structures.md @@ -85,6 +85,20 @@ options: { } ``` +When using keys of the form `foo.bar`, you can allow for escaping dot symbol and add a double slash before the dot. + +```javascript +type: 'doughnut', +data: { + datasets: [{ + data: [{ "data.key": "one", "data.value": 20 }, { "data.key": "two", "data.value": 30 }], + }] +}, +options: { + parsing: { xAxisKey: "data\\.key", yAxisKey: "data\\.value"}, +} +``` + :::warning When using object notation in a radar chart you still need a labels array with labels for the chart to show correctly. ::: diff --git a/src/helpers/helpers.core.js b/src/helpers/helpers.core.js index 00c143aa325..803efa1e320 100644 --- a/src/helpers/helpers.core.js +++ b/src/helpers/helpers.core.js @@ -304,6 +304,9 @@ export function resolveObjectKey(obj, key) { if (key === emptyString) { return obj; } + if (key.match(/[\\]/g)) { + return obj[key.replace(/[\\]/g, '')]; + } let pos = 0; let idx = indexOfDotOrLength(key, pos); while (obj && idx > pos) {