(
dom?: HTMLElement | null,
theme?: string | object | null,
opts?: EChartsInitOpts
)
| 2924 | * @param opts.useDirtyRect Enable dirty rectangle rendering or not. |
| 2925 | */ |
| 2926 | export function init( |
| 2927 | dom?: HTMLElement | null, |
| 2928 | theme?: string | object | null, |
| 2929 | opts?: EChartsInitOpts |
| 2930 | ): EChartsType { |
| 2931 | const isClient = !(opts && opts.ssr); |
| 2932 | if (isClient) { |
| 2933 | if (__DEV__) { |
| 2934 | if (!dom) { |
| 2935 | throw new Error('Initialize failed: invalid dom.'); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | const existInstance = getInstanceByDom(dom); |
| 2940 | if (existInstance) { |
| 2941 | if (__DEV__) { |
| 2942 | warn('There is a chart instance already initialized on the dom.'); |
| 2943 | } |
| 2944 | return existInstance; |
| 2945 | } |
| 2946 | |
| 2947 | if (__DEV__) { |
| 2948 | if (isDom(dom) |
| 2949 | && dom.nodeName.toUpperCase() !== 'CANVAS' |
| 2950 | && ( |
| 2951 | (!dom.clientWidth && (!opts || opts.width == null)) |
| 2952 | || (!dom.clientHeight && (!opts || opts.height == null)) |
| 2953 | ) |
| 2954 | ) { |
| 2955 | warn('Can\'t get DOM width or height. Please check ' |
| 2956 | + 'dom.clientWidth and dom.clientHeight. They should not be 0.' |
| 2957 | + 'For example, you may need to call this in the callback ' |
| 2958 | + 'of window.onload.'); |
| 2959 | } |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | const chart = new ECharts(dom, theme, opts); |
| 2964 | chart.id = 'ec_' + idBase++; |
| 2965 | instances[chart.id] = chart; |
| 2966 | |
| 2967 | isClient && modelUtil.setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id); |
| 2968 | |
| 2969 | enableConnect(chart); |
| 2970 | |
| 2971 | lifecycle.trigger('afterinit', chart); |
| 2972 | |
| 2973 | return chart; |
| 2974 | } |
| 2975 | |
| 2976 | /** |
| 2977 | * @usage |
searching dependent graphs…