简体   繁体   English

使用 Vue 谷歌图表 - Geochart。 图表在数据更改时重新加载,但图例被删除

[英]Using Vue Google Chart - Geochart. Chart reloads on data change, but legend gets dropped

I am using vue google charts in my nuxt project.我在我的 nuxt 项目中使用 vue 谷歌图表。 When I change date selections, the data is mutated, and the computed method in my geochart component reads the correct new data.... But the legend at the bottom (color bar) does not work like it should... Instead it reads NaN NaN...As a result, the chart shows the correct data, but not the correct color coding.当我更改日期选择时,数据发生了变化,我的 geochart 组件中的计算方法读取了正确的新数据......但底部(颜色条)的图例无法正常工作......相反,它读取NaN NaN...因此,图表显示了正确的数据,但没有正确的颜色编码。 Screenshot attached for clarity.为清楚起见,附上截图。 (Mouseover on the countries shows the correct data, but since the color mapping is not kicking in, the two countries show the same color shade, despite the values being significantly different) (国家/地区上的鼠标悬停显示正确的数据,但由于颜色映射没有启动,这两个国家显示相同的颜色阴影,尽管值显着不同)

This is how I am loading the chart:这是我加载图表的方式:

<GChart
  :settings="{ packages: ['geochart'], mapsApiKey: '<usingmapsapikeyhere>' }"
  type="GeoChart"
  :data="countriesForMap"
  :options="chartOptions"
  ref="gChart"
/>

countriesForMap ----国家地图----

computed: {
    ...mapState(["countriesForMap"]),
  }

在此处输入图片说明

I figured it out.我想到了。 Instead of updating the array, my mutation was appending new data to the same array, which was making the array unusable.我的变异不是更新数组,而是将新数据附加到同一个数组,这使数组无法使用。 I am not sure why it was still reflecting the correct data on the map, but now that I have changed the mutation code, it is working fine now.我不知道为什么它仍然在地图上反映正确的数据,但是现在我已经更改了突变代码,它现在工作正常。

For example, The initial array looked like例如,初始数组看起来像

[
["Country", "Data"],
["India", 42],
["Japan", 12]
]

Because of the wrongly set up mutation function, my new data array was looking like this:由于错误设置的突变函数,我的新数据数组如下所示:

[
["Country", "Data"],
["India", 42],
["Japan", 12],
["Country", "Data"],
["India", 23],
["Japan", 7]
]

Fixing that solved the problem.修复解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM