Added custom configs to Column Chart
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
const columnChart = () => {
|
const columnChart = () => {
|
||||||
return {
|
return {
|
||||||
@@ -23,6 +24,7 @@ const columnChart = () => {
|
|||||||
const grid = component.get('columnChartModel.grid');
|
const grid = component.get('columnChartModel.grid');
|
||||||
const columnWidth = component.get('columnChartModel.columnWidth');
|
const columnWidth = component.get('columnChartModel.columnWidth');
|
||||||
const horizontal = component.get('columnChartModel.horizontal');
|
const horizontal = component.get('columnChartModel.horizontal');
|
||||||
|
const jsonConfig = component.get('columnChartModel.jsonConfig');
|
||||||
|
|
||||||
const data = component.get('columnChartModel.data');
|
const data = component.get('columnChartModel.data');
|
||||||
const series = [{
|
const series = [{
|
||||||
@@ -107,7 +109,7 @@ const columnChart = () => {
|
|||||||
options['colors'] = colors
|
options['colors'] = colors
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
resources/js/helpers.js
Normal file
27
resources/js/helpers.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import deepmerge from 'deepmerge'
|
||||||
|
|
||||||
|
export const addPathToObjectWithValue = (obj, path, value) => {
|
||||||
|
const pList = path.split('.');
|
||||||
|
const key = pList.pop();
|
||||||
|
const pointer = pList.reduce((accumulator, currentValue) => {
|
||||||
|
if (accumulator[currentValue] === undefined) accumulator[currentValue] = {};
|
||||||
|
return accumulator[currentValue];
|
||||||
|
}, obj);
|
||||||
|
pointer[key] = value;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mergedOptionsWithJsonConfig = (options, jsonConfig) => {
|
||||||
|
const customOptions = Object.keys(jsonConfig)
|
||||||
|
.reduce(function (obj, key) {
|
||||||
|
const value = jsonConfig[key]
|
||||||
|
|
||||||
|
if (typeof value === 'string' && value.includes('function')) {
|
||||||
|
return addPathToObjectWithValue(obj, key, eval('(' + value + ')'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return addPathToObjectWithValue(obj, key, eval(value))
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
return deepmerge(options, customOptions)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user