Replies: 2 comments 6 replies
-
After looking around the source code I noticed the VisXYContainer has a watch() function and since I wasn't supplying my data to the container it indeed wasn't updating. So it seems to be possible.
|
Beta Was this translation helpful? Give feedback.
-
Reopening this to see if anyone can help improve this. Right now the animating of the lines messes the realtime part up (points are animated to their new point instead of moving sideways). I don't see any documentation on changing the animation for charts. <script lang="ts" setup>
import {VisArea, VisAxis, VisLine, VisXYContainer} from '@unovis/vue'
import type {DataRecord} from "~/utils/types";
import type {Ref} from "@vue/reactivity";
const data: Ref<DataRecord[]> = ref([
{x: 0, y: 0},
{x: 1, y: 2},
{x: 2, y: 1},
{x: 3, y: 1},
{x: 4, y: 3},
{x: 5, y: 1},
{x: 6, y: 5},
{x: 7, y: 1},
])
function updateData() {
data.value.splice(0, 1)
const lastX = data.value[data.value.length - 1].x
data.value.push({x: lastX + 1, y: Math.floor(Math.random() * 10)})
}
function calcXD() {
return [data.value.map(i => i.x)[0], data.value.map(i => i.x)[data.value.length - 1]]
}
function calcYD() {
// return [Math.min(...data.value.map(i => i.y)), Math.max(...data.value.map(i => i.y))]
return [0, 10]
}
</script>
<template>
<UButton class="absolute left-2 top-2" @click="updateData">Update</UButton>
<div class="!w-[32rem] !h-[32rem] flex flex-col">
<VisXYContainer :data="data" :margin="{top: 10, bottom: 0}"
:xDomain="calcXD()"
:yDomain="calcYD()"
class="grow">
<VisLine :color="`var(--vis-color${0})`" :x="(i: any) => i.x" :y="(i: any) => i.y"/>
<VisArea :color="`var(--vis-color${0})`" :opacity="0.2" :x="(i: any) => i.x"
:y="(i: any) => i.y"/>
<VisAxis :tickLine="false" type="x"/>
<VisAxis :gridLine="false" :tickLine="false" type="y"/>
</VisXYContainer>
<!-- <VisBulletLegend :items=""/>-->
</div>
</template>
<style scoped>
div {
--vis-color0: theme('colors.red.400');
--vis-color1: theme('colors.blue.400');
--vis-color2: theme('colors.yellow.400');
--vis-color3: theme('colors.green.400');
--vis-color4: theme('colors.purple.400');
--vis-color5: theme('colors.pink.400');
--vis-axis-tick-label-color: theme('colors.gray.700');
--vis-axis-grid-color: theme('colors.gray.700');
--vis-axis-tick-color: theme('colors.gray.700');
--vis-axis-label-color: theme('colors.gray.700');
}
</style> Suggestions on how to make this more like the chart I linked to in my initial message would be very welcome! |
Beta Was this translation helpful? Give feedback.
-
Hi, I recently discovered Unovis and was wondering if it does support realtime charts?
Something similar to what apexcharts has.
When I dynamically update a ref value (I'm using Vue for my project), the chart itself does not update.
If anyone can let me know if Unovis has support for this I would greatly appreciate it.
Here is what my component currently looks like. Note that I am still new to web development so there might be a better way of doing this.
Beta Was this translation helpful? Give feedback.
All reactions