diff --git a/frontend/src/Editor/Components/Chart.jsx b/frontend/src/Editor/Components/Chart.jsx index e79380d2b0..3ababc96c9 100644 --- a/frontend/src/Editor/Components/Chart.jsx +++ b/frontend/src/Editor/Components/Chart.jsx @@ -9,6 +9,7 @@ export const Chart = function Chart({ console.log('currentState', currentState); const [loadingState, setLoadingState] = useState(false); + const [chartData, setChartData] = useState([]); useEffect(() => { const loadingStateProperty = component.definition.properties.loadingState; @@ -27,11 +28,6 @@ export const Chart = function Chart({ const dataProperty = component.definition.properties.data; const dataString = dataProperty ? dataProperty.value : []; - let data = []; - try { - data = JSON.parse(dataString); - } catch (err) { console.log(err); } - const titleProperty = component.definition.properties.title; const title = titleProperty.value; @@ -44,13 +40,6 @@ export const Chart = function Chart({ const gridLinesProperty = component.definition.properties.showGridLines; const showGridLines = gridLinesProperty ? gridLinesProperty.value : true; - const chartData = [{ - type: chartType || 'line', - x: data.map((item) => item["x"]), - y: data.map((item) => item["y"]), - marker: { color: markerColor } - }]; - const layout = { width, height, @@ -65,6 +54,26 @@ export const Chart = function Chart({ } } + useEffect(() => { + let data = resolveReferences(dataString, currentState, []); + + if(typeof data === 'string') { + try { + data = JSON.parse(dataString); + } catch (err) { data = []; } + } + + const newData = [{ + type: chartType || 'line', + x: data.map((item) => item["x"]), + y: data.map((item) => item["y"]), + marker: { color: markerColor } + }]; + + setChartData(newData); + + }, [dataString]); + return (