Skip to content

Commit 957d519

Browse files
authored
Updates to Updating Charts documentation (#1082)
* Update index.md - updated documentation for `updating charts` section * Update index.md - also updated Korean translation (i'm korean) regarding updating chart * Update index.md
1 parent 8ca163b commit 957d519

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

website/src/guide/index.md

+16
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ export default {
125125
</script>
126126
```
127127

128+
You may get Vue's `Target is readonly` warnings when you are updating your `chartData`.
129+
130+
If your `chartData` is a `read-only` reactive value, you can override this warning by using a clone:
131+
132+
```vue
133+
<template>
134+
<Bar :data="JSON.stringify(JSON.parse(chartData))" :options="chartOptions" />
135+
</template>
136+
```
137+
138+
Unless you have a writable computed `chartData`, you won't be able to use the newer `structuredClone`, as you'll likely hit the `Write operation failed: computed value is readonly` error.
139+
140+
You don't need to use a clone if your `chartData` is a [writable computed value](https://vuejs.org/guide/essentials/computed#writable-computed).
141+
142+
143+
128144
## Access to Chart instance
129145

130146
You can get access to chart instance via template refs.

website/src/kr/guide/index.md

+30-19
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,45 @@ export default {
9696

9797
## 차트 데이터 업데이트
9898

99-
Chart.js 자체는 데이터 세트를 변경할 때 라이브 업데이트 기능을 제공하지 않습니다. 그러나 `vue-chartjs`는 이것을 실현하기 위해 2 개의 mixin을 제공합니다.
99+
v4부터 차트는 기본적으로 데이터 변경 `watch`와 옵션 변경 `watch`가 있으므로 새 데이터 또는 새 옵션이 전달되면 (변경되면) Vue Chart 래퍼가 차트를 업데이트하거나 다시 렌더링합니다. v4부터는 믹스인이 제거되었습니다.
100100

101-
- `reactiveProp`
102-
- `reactiveData`
103-
104-
두 믹스 인은 실제로 동일한 결과를 얻습니다. 대부분의 경우 `reactiveProp`을 사용합니다. 이 믹스인은 차트 컴포넌트의 로직을 확장하고 자동으로 `chartData`라는 속성을 생성하고 이 속성에 `vue watch`를 추가합니다. 데이터가 변경되면, 데이터 세트내의 데이터만이 변경되고 있으면 `update()`를, 새로운 데이터 세트가 추가되고 있으면 `renderChart()`를 호출합니다.
101+
### 예제
105102

106-
`ractiveData`는 속성이 아닌 로컬 chartData 변수를 만들고 Watcher를 추가합니다. 이것은 단일 목적 차트가 필요하고 차트 구성 요소 내에서 API 호출을 수행하는 경우에만 유용합니다.
103+
```vue
104+
<template>
105+
<Bar :data="chartData" :options="chartOptions" />
106+
</template>
107107
108-
### 예제
108+
<script>
109+
// DataPage.vue
110+
import { Bar } from 'vue-chartjs'
111+
import { Chart as ChartJS, Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale } from 'chart.js'
109112
110-
**LineChart.js**
111-
```javascript
112-
import { Line, mixins } from 'vue-chartjs'
113-
const { reactiveProp } = mixins
113+
ChartJS.register(Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale)
114114
115115
export default {
116-
extends: Line,
117-
mixins: [reactiveProp],
118-
props: ['options'],
119-
mounted () {
120-
// this.chartData is created in the mixin.
121-
// If you want to pass options please create a local options object
122-
this.renderChart(this.chartData, this.options)
123-
}
116+
name: 'BarChart',
117+
components: { Bar },
118+
computed: {
119+
chartData() { return /* mutable chart data */ },
120+
chartOptions() { return /* mutable chart options */ }
121+
}
124122
}
123+
</script>
125124
```
126125

126+
차트 데이터를 업데이트할 때 Vue의 `Target is read only` 경고가 나타날 수 있습니다.
127+
128+
데이터가 '읽기 전용' (`read only`) 반응 값인 경우 클론을 사용하여 이 경고를 재정의할 수 있습니다
129+
130+
```vue
131+
<template>
132+
<Bar :data="JSON.stringify(JSON.parse(chartData))" :options="chartOptions" />
133+
</template>
134+
```
135+
136+
차트 데이터가 수정 가능한 계산된 속성 경우 [writable computed value](https://vuejs.org/guide/essentials/computed#writable-computed) 클론을 사용할 필요가 없습니다
137+
127138
**RandomChart.vue**
128139

129140
```javascript

0 commit comments

Comments
 (0)