Components
<VChartLight>
Enable simple interactions on the client side based on server-side rendering.
<VChartLight>
uses <VChartServer>
underhood to render ECharts on server side. The SVG rendered by the server is hydrated with ECharts lightweight client runtime to enable some simple interactions such as: clicking the legend to toggle whether the series is displayed. In this case, we can avoid loading at least a few hundred KBs of ECharts code on the client side.
app/components/example.vue
<script setup>
const option = ref({
legend: {
selected: {
a: true,
b: true,
c: true,
},
},
series: [
{
name: 'Access From',
type: 'pie',
roseType: 'angle',
data: [
{ value: 800, name: 'a' },
{ value: 735, name: 'b' },
{ value: 580, name: 'c' },
],
},
],
})
function onClick(params) {
if (params.ssrType === 'legend') {
const key = Object.keys(option.value.legend.selected)[params.dataIndex]
// toggle display of the series
option.value.legend.selected[key] = !option.value.legend.selected[key]
}
}
</script>
<template>
<VChartLight :option="option" @click="onClick" />
</template>
Props
init-options
: Optional chart init configurations. Seeecharts.init
'sopts
parameter.- type:
object
- Injection key:
INIT_OPTIONS_KEY
.
- type:
We have to specify the
height
and width
property in init-options
for SSR.theme
: Theme to be applied. Seeecharts.init
'stheme
parameter.- type:
string
orobject
- Injection key:
THEME_KEY
.
- type:
option
: ECharts' universal interface. Modifying this prop will trigger ECharts'setOption
method. Read more here →.- type:
object
- type:
Events
click
- parameters:
- params:
- type:
ECSSRClientEventParams
- type:
- params:
- parameters:
mouseout
- parameters:
- params:
- type:
ECSSRClientEventParams
- type:
- params:
- parameters:
mouseover
- parameters:
- params:
- type:
ECSSRClientEventParams
- type:
- params:
- parameters:
export interface ECSSRClientEventParams {
type: 'mouseover' | 'mouseout' | 'click';
ssrType: 'legend' | 'chart';
seriesIndex?: number;
dataIndex?: number;
event: Event;
}