Your first chart
Mount the Vue workbench and load its built-in example data.
This example selects the built-in MOCK-100 instrument. Its candles are generated locally for testing the chart.
<script setup lang="ts">
import { onScopeDispose } from 'vue'
import { KlineWorkbench, createPersistedMarketDataHost, provideBrowserAppRuntime } from '@363045841yyt/klinechart'
import '@363045841yyt/klinechart/style.css'
const host = createPersistedMarketDataHost()
provideBrowserAppRuntime(host.context, true, console.error)
onScopeDispose(() => host.dispose())
</script>
<template>
<KlineWorkbench
style="height: 480px"
:instrument="{ source: 'mock', id: 'mock:MOCK-100' }"
period="daily"
/>
</template>To connect an application data feed, create a market data host, register your MarketDataSource, and pass the host to provideBrowserAppRuntime. Select an instrument by its source and stable ID. Dispose of the host when your application no longer uses it.
import { createMarketDataHost, type MarketDataSource } from '@363045841yyt/klinechart'
export function connectMarketData(source: MarketDataSource) {
const marketDataContext = createMarketDataHost()
marketDataContext.registerDataSource(source)
return marketDataContext
}For a customized Agent host, import getChartAgentClient from @363045841yyt/klinechart/agent. See the Agent tool reference for the chart tools and their parameter schemas.