|
@@ -4,13 +4,13 @@
|
|
|
<el-button v-if="tab === '0'" size="small" type="primary">
|
|
|
收视率
|
|
|
</el-button>
|
|
|
- <el-button v-else size="small" @click="()=>change('0')">
|
|
|
+ <el-button v-else size="small" @click="() => change('0')">
|
|
|
收视率
|
|
|
</el-button>
|
|
|
<el-button v-if="tab === '1'" size="small" type="primary">
|
|
|
市占率
|
|
|
</el-button>
|
|
|
- <el-button v-else size="small" @click="()=>change('1')">
|
|
|
+ <el-button v-else size="small" @click="() => change('1')">
|
|
|
市占率
|
|
|
</el-button>
|
|
|
</el-button-group>
|
|
@@ -19,7 +19,24 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import * as echarts from "echarts";
|
|
|
+// import * as echarts from "echarts";
|
|
|
+
|
|
|
+import * as echarts from "echarts/core";
|
|
|
+import { BarChart } from "echarts/charts";
|
|
|
+import {
|
|
|
+ TitleComponent,
|
|
|
+ TooltipComponent,
|
|
|
+ GridComponent,
|
|
|
+} from "echarts/components";
|
|
|
+import { CanvasRenderer } from "echarts/renderers";
|
|
|
+echarts.use([
|
|
|
+ TitleComponent,
|
|
|
+ TooltipComponent,
|
|
|
+ GridComponent,
|
|
|
+ BarChart,
|
|
|
+ CanvasRenderer,
|
|
|
+]);
|
|
|
+
|
|
|
export default {
|
|
|
name: "bilateralBarChart",
|
|
|
props: ["list", "keyName"],
|
|
@@ -34,19 +51,19 @@ export default {
|
|
|
leftList: [],
|
|
|
rightList: [],
|
|
|
chart: undefined,
|
|
|
- tab: "0"
|
|
|
+ tab: "0",
|
|
|
};
|
|
|
},
|
|
|
filters: {},
|
|
|
methods: {
|
|
|
- change(type){
|
|
|
+ change(type) {
|
|
|
this.tab = type;
|
|
|
- if(!this.chart) return;
|
|
|
+ if (!this.chart) return;
|
|
|
let source = this.formatte();
|
|
|
this.chart.setOption({
|
|
|
title: [
|
|
|
{
|
|
|
- text: this.tab === '0' ? "收视率" : "市占率",
|
|
|
+ text: this.tab === "0" ? "收视率" : "市占率",
|
|
|
left: "center",
|
|
|
textAlign: "center",
|
|
|
},
|
|
@@ -56,7 +73,7 @@ export default {
|
|
|
type: "category",
|
|
|
gridIndex: 0,
|
|
|
data: source[this.tab].texts.reverse(),
|
|
|
- }
|
|
|
+ },
|
|
|
],
|
|
|
series: [
|
|
|
{
|
|
@@ -74,7 +91,7 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
],
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
read(v) {
|
|
|
if (isNaN(v)) return 0;
|
|
@@ -114,10 +131,10 @@ export default {
|
|
|
this.chart.resize({
|
|
|
height: (this.$refs.bilateralBarChart.offsetWidth * 9) / 16,
|
|
|
});
|
|
|
- var option = ({
|
|
|
+ var option = {
|
|
|
title: [
|
|
|
{
|
|
|
- text: this.tab === '0' ? "收视率" : "市占率",
|
|
|
+ text: this.tab === "0" ? "收视率" : "市占率",
|
|
|
left: "center",
|
|
|
textAlign: "center",
|
|
|
},
|
|
@@ -132,12 +149,10 @@ export default {
|
|
|
type: "category",
|
|
|
gridIndex: 0,
|
|
|
data: source[this.tab].texts.reverse(),
|
|
|
- interval:0
|
|
|
- }
|
|
|
- ],
|
|
|
- xAxis: [
|
|
|
- { gridIndex: 0, position: "top" },
|
|
|
+ interval: 0,
|
|
|
+ },
|
|
|
],
|
|
|
+ xAxis: [{ gridIndex: 0, position: "top" }],
|
|
|
grid: { left: 150, top: "15%", buttom: 0, right: "10%" },
|
|
|
series: [
|
|
|
{
|
|
@@ -155,7 +170,7 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
],
|
|
|
- });
|
|
|
+ };
|
|
|
|
|
|
option && this.chart.setOption(option);
|
|
|
},
|