@@ -9,7 +9,7 @@ import { AxisFormatterComp, EchartsAxisType } from "./chartConfigs/cartesianAxis
99import { chartChildrenMap , ChartSize , getDataKeys } from "./chartConstants" ;
1010import { chartPropertyView } from "./chartPropertyView" ;
1111import _ from "lodash" ;
12- import { useEffect , useMemo , useRef , useState } from "react" ;
12+ import { useContext , useEffect , useMemo , useRef , useState } from "react" ;
1313import ReactResizeDetector from "react-resize-detector" ;
1414import ReactECharts from "./reactEcharts" ;
1515import {
@@ -24,6 +24,8 @@ import {
2424 withDefault ,
2525 withExposingConfigs ,
2626 withViewFn ,
27+ ThemeContext ,
28+ chartColorPalette ,
2729} from "openblocks-sdk" ;
2830import { getEchartsLocale , trans } from "i18n/comps" ;
2931import { ItemColorComp } from "comps/chartComp/chartConfigs/lineChartConfig" ;
@@ -32,6 +34,7 @@ import {
3234 getEchartsConfig ,
3335 getSelectedPoints ,
3436} from "comps/chartComp/chartUtils" ;
37+ import log from "loglevel" ;
3538
3639let ChartTmpComp = ( function ( ) {
3740 return new UICompBuilder ( chartChildrenMap , ( ) => null )
@@ -43,6 +46,17 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
4346 const echartsCompRef = useRef < ReactECharts | null > ( ) ;
4447 const [ chartSize , setChartSize ] = useState < ChartSize > ( ) ;
4548 const firstResize = useRef ( true ) ;
49+ const theme = useContext ( ThemeContext ) ;
50+ const defaultChartTheme = {
51+ color : chartColorPalette ,
52+ backgroundColor : "#fff" ,
53+ } ;
54+ let themeConfig = defaultChartTheme ;
55+ try {
56+ themeConfig = theme ?. theme . chart ? JSON . parse ( theme ?. theme . chart ) : defaultChartTheme ;
57+ } catch ( error ) {
58+ log . error ( 'theme chart error: ' , error ) ;
59+ }
4660 const onEvent = comp . children . onEvent . getView ( ) ;
4761 useEffect ( ( ) => {
4862 // bind events
@@ -94,6 +108,7 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
94108 lazyUpdate
95109 opts = { { locale : getEchartsLocale ( ) } }
96110 option = { option }
111+ theme = { themeConfig }
97112 />
98113 </ ReactResizeDetector >
99114 ) ;
0 commit comments