javascript - 为什么当图表类型发生变化时,apexchart 不能在 vue(spa) 中正确呈现?
问题描述
我有一个带有 3 种图表的 v-tab 项目栏,都必须显示来自单个变量的数据。从 v-select 中选择一个选项后,变量正在更新。它第一次正确呈现,但是在更改选项后,所有数据都会在除 xaxis 类别之外的所有图表中正确呈现。xaxis 值不会出现在刻度上。但在工具提示视图中可见。在调整窗口大小时,数据再次出现,无法在更改时强制呈现图表。需要一些帮助。
<v-tabs
center-active
v-model="ctab"
color="#a24187"
slider-color="#a24187"
>
<v-tab >
<v-icon color="#2E93fA">mdi-poll</v-icon> Bar</v-tab
>
<v-tab >
<v-icon color="#2E93fA">mdi-chart-timeline-variant</v-icon>Line
</v-tab>
<v-tab >
<v-icon color="#2E93fA">mdi-scatter-plot</v-icon> Scatter</v-tab
>
</v-tabs>
<v-tabs-items v-model="ctab" class="px-2">
<v-tab-item>
<apexchart
ref="chart"
width="700"
height="260"
type="bar"
:options="chartoptions"
:series="sr"
></apexchart>
</v-tab-item>
<v-tab-item>
<apexchart
ref="chart"
width="700"
height="260"
type="line"
:options="chartoptions"
:series="sr"
></apexchart>
</v-tab-item>
<v-tab-item>
<apexchart
ref="chart"
width="700"
height="260"
type="scatter"
:options="chartoptions"
:series="sr"
></apexchart>
</v-tab-item>
</v-tabs-items>
正在使用的变量和属性
sr: [
{
name: "",
data: [],
},
],
chartoptions: {
chart: {
id: "UNChart",
},
xaxis: {
categories: [],
axisBorder: {
show: true,
color: "#a24187",
height: 1,
width: "100%",
offsetX: 0,
offsetY: 0,
},
axisTicks: {
show: true,
borderType: "solid",
color: "#a24187",
height: 6,
offsetX: 0,
offsetY: 0,
},
},
yaxis: {
axisBorder: {
show: true,
color: "#a24187",
offsetX: 0,
offsetY: 0,
},
axisTicks: {
show: true,
borderType: "solid",
color: "#a24187",
width: 6,
offsetX: 0,
offsetY: 0,
},
},
title: {
text: undefined,
align: "left",
margin: 10,
offsetX: 0,
offsetY: 0,
floating: false,
style: {
fontSize: "14px",
fontWeight: "bold",
fontFamily: undefined,
color: "#263238",
},
},
},
用于获取数据的方法
showchart() {
this.tempData = [];
this.tempCategory = [];
this.sr[0].data = [];
this.sr[0].name = "";
this.chartoptions.xaxis.categories = [];
for (let index = 0; index < this.newdata.length; index++) {
if (this.criteria === this.newdata[index].specific_title) {
this.tempData.push(this.newdata[index].current_value);
this.tempCategory.push(this.newdata[index].specific_name);
}
}
// ApexCharts.exec(
// "UNChart",
// "updateOptions",
// {
// xaxis: {
// categories: this.tempCategory,
// },
// },
// false,
// true
// );
// ApexCharts.exec(
// "UNChart",
// "updateSeries",
// [
// {
// data: this.tempData,
// name: this.criteria,
// },
// ],
// true
// );
this.sr = [
{
name: this.criteria,
data: this.tempData,
},
];
this.chartoptions = {
...this.chartoptions,
...{
xaxis: { categories: this.tempCategory },
title: { text: this.filter.theme.name },
},
};
// this.$refs.chart.updateOptions({ xaxis: { categories: this.tempCategory } });
},
解决方案
推荐阅读
- cordova - 无法上传相机拍摄的照片。使用 apache cordova 和 Visual Studio
- android - ImageView 不在 CardView 中的中心
- r - 使用 Shiny 响应式地提供图像
- php - 不显示已删除的天数,并显示下一个可用天数
- java - 卡在 JavaFX 列表视图中
- vue.js - 从递归子组件更新父数据
- python - 日期时间 OSError:[Errno 22] 无效参数
- android - 来自 Sqlite 数据库的实时数据通过 Activity/Fragment 外的 Room 遵循 MVVM 模型
- java - 蒙特卡洛掷骰子和比特币模拟
- mysql - 通过不给出正确的输出作为负 (-) 大于正 (+) 的 ascii 值来排序