Vue and React
<script setup lang="ts">
import { ref } from 'vue';
import { KumoProChart } from '@kumo-charts/pro-chart/vue';
const symbol = ref('600519.SH');
const theme = ref<'light' | 'dark'>('light');
</script>
<template>
<div style="height: 600px">
<KumoProChart
:options="{ datafeed, upColor: 'red', theme }"
v-model:symbol="symbol"
@indicators-change="save"
@button-click="({ id }) => id === 'trade' && openTicket()"
@created="(c) => (chart = c)"
/>
</div>
</template>import { KumoProChart } from '@kumo-charts/pro-chart/react';
const options = useMemo(() => ({ datafeed, upColor: 'red', theme }), [theme]);
<div style={{ height: 600 }}>
<KumoProChart
options={options}
symbol={symbol}
onSymbolChange={(event) => setSymbol(event.symbol)}
onIndicatorsChange={save}
onCreated={setChart}
/>
</div>;- The component is
KumoProChart, the counterpart of the open-sourceKumoChart; the chart objectcreateProChart()returns is of the typeProChart. - What
applyOptions()can change inoptions(the theme, the language, colors, texts of the interface, feature toggles, buttons and menus, the watchlist, the drawing toolbar, …) follows along: pass a new object (in Vue, changing a key of a reactive object counts too), and what changed is applied withapplyOptions(), while what was taken out goes back to the default;features,messagesandthemesare merged key by key as withapplyOptions(). Options such asdatafeed,storageandcustomIndicatorsare read only once, when mounting. In React, keep the object the same while it has not changed, withuseMemoor the like, rather than making a new one on every render. Everything else goes through the chart object handed over bycreated. symbolandtimeframecan be bound as props: when a prop changes, the chart follows. Bound,symbolandtimeframeare decided by the page, on opening too, rather than restoring what the user looked at last; Vue binds them both ways withv-model:symbolandv-model:timeframe, and React pairs them withonSymbolChangeandonTimeframeChange. Withsymbolbound,optionscan leave it out.- When the chart does not accept what the page gives (a symbol the datafeed cannot find, a timeframe not offered, a wrong option, …), it stays as it was, and
@prop-errorin Vue andonPropErrorin React receive{ prop, value, error }:propissymbol,timeframeoroptions,valuethe value the page gave (foroptions, the options that changed), anderrorthe error of the method that rejected it (setSymbol(),setTimeframe(),applyOptions()). Without a listener, the error is thrown as an unhandled Promise rejection, seen in the browser console. Props whose turn had not come yet when the component unmounts are not reported. - Every event can be listened to directly: in Vue
@symbol-change,@indicators-change,@crosshair-move, …, in ReactonSymbolChange,onIndicatorsChange,onCrosshairMove, …, always calling the function given by the latest render.created(onCreatedin React) hands over the chart object when the component mounts, without waiting for the first chart to be made;ready, like other events, is emitted once the first chart is made. - React 18 and 19 are supported, StrictMode included.