• <small id='uAEqV'></small><noframes id='uAEqV'>

      • <bdo id='uAEqV'></bdo><ul id='uAEqV'></ul>
      <legend id='uAEqV'><style id='uAEqV'><dir id='uAEqV'><q id='uAEqV'></q></dir></style></legend>

      <tfoot id='uAEqV'></tfoot>
      <i id='uAEqV'><tr id='uAEqV'><dt id='uAEqV'><q id='uAEqV'><span id='uAEqV'><b id='uAEqV'><form id='uAEqV'><ins id='uAEqV'></ins><ul id='uAEqV'></ul><sub id='uAEqV'></sub></form><legend id='uAEqV'></legend><bdo id='uAEqV'><pre id='uAEqV'><center id='uAEqV'></center></pre></bdo></b><th id='uAEqV'></th></span></q></dt></tr></i><div id='uAEqV'><tfoot id='uAEqV'></tfoot><dl id='uAEqV'><fieldset id='uAEqV'></fieldset></dl></div>

        vue-chartjs 反应数据错误

        vue-chartjs reactive data error(vue-chartjs 反应数据错误)

              <tbody id='jEAeu'></tbody>

            <i id='jEAeu'><tr id='jEAeu'><dt id='jEAeu'><q id='jEAeu'><span id='jEAeu'><b id='jEAeu'><form id='jEAeu'><ins id='jEAeu'></ins><ul id='jEAeu'></ul><sub id='jEAeu'></sub></form><legend id='jEAeu'></legend><bdo id='jEAeu'><pre id='jEAeu'><center id='jEAeu'></center></pre></bdo></b><th id='jEAeu'></th></span></q></dt></tr></i><div id='jEAeu'><tfoot id='jEAeu'></tfoot><dl id='jEAeu'><fieldset id='jEAeu'></fieldset></dl></div>

            <tfoot id='jEAeu'></tfoot>

              <bdo id='jEAeu'></bdo><ul id='jEAeu'></ul>
            • <legend id='jEAeu'><style id='jEAeu'><dir id='jEAeu'><q id='jEAeu'></q></dir></style></legend>

                1. <small id='jEAeu'></small><noframes id='jEAeu'>

                  本文介绍了vue-chartjs 反应数据错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试为 vue-chartjs 使用响应式数据混合

                  I am trying to use reactive data mixin for vue-chartjs

                  设置初始数据的挂载函数正在运行,我可以使用 API 响应正确查看图表:

                  The mounted function to set the initial data is working and I can see the chart correctly using the API response:

                  fetchSessionTrends() {
                      axios.get(endpoint)
                      .then(({data}) => {
                          this.sessions = data.map(session => session.sessions);
                          this.sessionLabels = data.map(label => label.date);
                          this.loaded = true;
                      });
                  },
                  

                  数据:

                  data() {
                      return {
                         endpoint: 'public/api/sessions',
                         sessions: [],
                         sessionLabels: [],
                         loaded: false,
                         daysFilter: 14
                      };
                  },
                  

                  我正在显示带有文本字段的图表以提供反应部分 - 期望它再次调用端点并接收新响应

                  I am display the chart with a text field to provide the reactive portion - expectation is that it calls the endpoint again and receives new response

                  <div class="col-md-2 session-filter">
                      <div class="input-group">
                      <input type="text" class="form-control" placeholder="days..." v-model="daysFilter">
                      <span class="input-group-btn">
                        <button class="btn btn-secondary" type="button" @click="refreshSessions">Go</button>
                      </span>
                      </div>
                  </div>
                  <line-chart v-if="loaded" :chart-data="sessions" :chart-labels="sessionLabels"></line-chart>
                  

                  然而,为了测试反应部分,现在我只是直接更改数据数组以查看它是如何工作的:

                  To test the reactive part however, for now I am simply changing the data arrays directly to see how it works:

                  refreshSessions() {          
                     this.sessions = [1, 2, 3];
                     this.sessionlabels = ["june", "july", "august"];  
                  },
                  

                  是的,所以这给了我错误

                  Right, so this is giving me the errors

                  [Vue warn]: Error in callback for watcher "chartData": "TypeError: Cannot read property 'map' of undefined" found in ....
                  
                   TypeError: Cannot read property 'map' of undefined
                  

                  LineChart.js 如文档中所述,此处缩写为空格

                  LineChart.js is as described in the docs, abbreviated here for space

                  import { Line, mixins } from 'vue-chartjs';
                  const { reactiveProp } = mixins
                  
                  extends: Line,
                  mixins: [reactiveProp],
                  props: {
                   chartData: {
                     type: Array,
                     required: true
                   },
                   chartLabels: {
                     type: Array,
                     required: true
                   }
                  },
                  
                  mounted() {
                    this.renderChart({
                      labels: this.chartLabels,
                      datasets: [
                        {
                          label: 'sessions',
                          data: this.chartData
                        }
                      ]
                    }, this.options)
                  }
                  

                  所以,图表最初工作正常,但我似乎无法让反应部分工作.

                  So, chart is initially working fine but I can't seem to get the reactive part working.

                  推荐答案

                  这行不通.因为 reactiveMixins 假设 chartData 是整个 chartjs 数据集对象.使用数据集数组,使用标签等.

                  This will not work. Because the reactiveMixins assume that chartData is the whole chartjs dataset object. With the dataset array, with the labels etc.

                  但是你把它分开了,这样反应混合器就不能工作了.因为你的chartData只是一个数据集的纯数据.

                  But you are splitting it up, this way the reactiveMixins can't work. Because your chartData is only the pure data of one dataset.

                  要解决它,你可以做两件事:

                  To solve it, you can do two things:

                  1. 传入整个数据集对象
                  2. 添加自己的观察者.

                  我想最简单的方法是添加两个观察者来观察 chartDatachartLabel 并在更改调用 this.$data._chart.update()

                  I guess the most simple method would be to add two watchers to watch chartData and chartLabel and on a change call this.$data._chart.update()

                  这篇关于vue-chartjs 反应数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                  Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                  How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)
                  Show data values in Chart.js bars (version 3)(在 Chart.js 条形图中显示数据值(版本 3))
                  Chart.js show x-axis data from right to left(Chart.js 从右到左显示 x 轴数据)
                  ChartJS - Finding the minimum and maximum labels that are inside a pan (When zooming)(ChartJS - 查找平底锅内的最小和最大标签(缩放时))

                2. <small id='NiHyk'></small><noframes id='NiHyk'>

                3. <i id='NiHyk'><tr id='NiHyk'><dt id='NiHyk'><q id='NiHyk'><span id='NiHyk'><b id='NiHyk'><form id='NiHyk'><ins id='NiHyk'></ins><ul id='NiHyk'></ul><sub id='NiHyk'></sub></form><legend id='NiHyk'></legend><bdo id='NiHyk'><pre id='NiHyk'><center id='NiHyk'></center></pre></bdo></b><th id='NiHyk'></th></span></q></dt></tr></i><div id='NiHyk'><tfoot id='NiHyk'></tfoot><dl id='NiHyk'><fieldset id='NiHyk'></fieldset></dl></div>

                  <tfoot id='NiHyk'></tfoot>
                    <tbody id='NiHyk'></tbody>

                      <bdo id='NiHyk'></bdo><ul id='NiHyk'></ul>
                      <legend id='NiHyk'><style id='NiHyk'><dir id='NiHyk'><q id='NiHyk'></q></dir></style></legend>