123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <template>
- <div>
- <div id='main'></div>
- </div>
- </template>
- <script>
- import * as echarts from 'echarts/core'
- import {
- DatasetComponent,
- TitleComponent,
- TooltipComponent,
- GridComponent,
- TransformComponent,
- } from 'echarts/components'
- import { LineChart } from 'echarts/charts'
- import { LabelLayout, UniversalTransition } from 'echarts/features'
- import { CanvasRenderer } from 'echarts/renderers'
- echarts.use([
- DatasetComponent,
- TitleComponent,
- TooltipComponent,
- GridComponent,
- TransformComponent,
- LineChart,
- CanvasRenderer,
- LabelLayout,
- UniversalTransition,
- ])
- export default {
- name: 'dataPlayBack',
- data() {
- return {
- //eCharts
- myChart: '',
- //开始和结束时间
- // 查询参数
- startTime: '2023-01-02 00:00:00',
- endTime: '2023-01-02 06:00:00',
- }
- },
- mounted() {
- this.creatECharts()
- },
- methods: {
- creatECharts() {
- if (this.myChart) {
- this.myChart.dispose()
- }
- var dom = document.getElementById('main')
- this.myChart = echarts.init(dom, null, {
- renderer: 'canvas',
- useDirtyRect: false,
- })
- let option
- const a = [
- ['Income', 'Life Expectancy', 'Population', 'Country', 'Year'],
- [615, 34.05, 251014, 'Finland', '2023-01-02 00:00:00'],
- [315, 34.05, 251014, 'Finland', '2023-01-02 01:00:00'],
- [725, 34.05, 251014, 'Finland', '2023-01-02 02:00:00'],
- [315, 34.05, 251014, 'Finland', '2023-01-02 03:00:00'],
- [515, 34.05, 251014, 'Finland', '2023-01-02 04:00:00'],
- [815, 34.05, 351014, 'Finland', '2023-01-02 05:00:00'],
- [1815, 34.05, 351014, 'Finland', '2023-01-02 06:00:00'],
- [814, 39, 645526, 'France', '2023-01-02 00:00:00'],
- [144, 39, 645526, 'France', '2023-01-02 01:00:00'],
- [454, 39, 645526, 'France', '2023-01-02 02:00:00'],
- [734, 39, 645526, 'France', '2023-01-02 03:00:00'],
- [144, 39, 645526, 'France', '2023-01-02 04:00:00'],
- [999, 39, 645526, 'France', '2023-01-02 05:00:00'],
- [814, 39, 645526, 'France', '2023-01-02 06:00:00'],
- ]
- let that = this
- run(a)
- function run(_rawData) {
- const countries = ['Finland', 'France']
- const datasetWithFilters = []
- const seriesList = []
- echarts.util.each(countries, function (country) {
- var datasetId = 'dataset_' + country
- datasetWithFilters.push({
- id: datasetId,
- fromDatasetId: 'dataset_raw',
- transform: {
- type: 'filter',
- config: {
- and: [
- {
- dimension: 'Year',
- gte: that.startTime,
- parser: 'time',
- },
- {
- dimension: 'Year',
- lt: that.endTime,
- parser: 'time',
- },
- { dimension: 'Country', '=': country },
- ],
- },
- },
- })
- seriesList.push({
- type: 'line',
- datasetId: datasetId,
- showSymbol: false,
- name: country,
- endLabel: {
- show: true,
- formatter: function (params) {
- return params.value[3] + ': ' + params.value[0]
- },
- },
- labelLayout: {
- moveOverlap: 'shiftY',
- },
- emphasis: {
- focus: 'series',
- },
- encode: {
- x: 'Year',
- y: 'Income',
- label: ['Country', 'Income'],
- itemName: 'Year',
- tooltip: ['Income'],
- },
- })
- })
- option = {
- animationDuration: that.speed,
- dataset: [
- {
- id: 'dataset_raw',
- source: _rawData,
- },
- ...datasetWithFilters,
- ],
- title: {
- text: '',
- },
- tooltip: {
- order: 'valueDesc',
- trigger: 'axis',
- },
- xAxis: {
- type: 'category',
- nameLocation: 'middle',
- },
- yAxis: {
- name: 'Income',
- },
- grid: {
- right: 140,
- },
- series: seriesList,
- }
- that.myChart.setOption(option)
- }
- },
- }
- }
- </script>
- <style scoped>
- #main {
- width: 1200px;
- height: 500px;
- }
- </style>
|