最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+阿里的G2圖表-antv+折線圖實例

 更新時間:2022年04月28日 10:09:52   作者:浩星  
這篇文章主要介紹了vue+阿里的G2圖表-antv+折線圖實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

vue阿里的G2圖表-antv+折線圖

之前使用的圖表是echarts+highcharts兩個常用圖表的,現(xiàn)在的話因為項目需要和別的原因也接觸使用了阿里的g2圖表,感覺效果還是挺好的,在這里分享下

官網(wǎng)入口

實現(xiàn)效果

實現(xiàn)步驟

第一:安裝插件

npm install @antv/g2 --save

第二:lineCharts.vue,注意,圖表這類型的數(shù)據(jù)必須mouned賦值一次,watch監(jiān)聽到數(shù)據(jù)改變在賦值一次,因為這里綁定的數(shù)據(jù)傳過來后并不會同時加載圖表

<template>
? <div class="gcharts" :id="id"></div>
</template>
<script>
import G2 from '@antv/g2'
export default {
? data () {
? ? return {
? ? ? chart: null
? ? }
? },
? props: {
? ? charData: {
? ? ? type: Array,
? ? ? default: function () {
? ? ? ? return {
? ? ? ? ? data: []
? ? ? ? }
? ? ? }
? ? },
? ? id: String
? },
? // 如果使用serverData傳過來的靜態(tài)數(shù)據(jù) 請使用mounted()方法 并注釋掉watch
? mounted () {
? ? this.drawChart()
? },
? // 監(jiān)聽API接口傳過來的數(shù)據(jù) 使用watch
? // watch: {
? ? ? // charData: function (val, oldVal) { ? ?// 監(jiān)聽charData,當(dāng)發(fā)生變化時,觸發(fā)這個回調(diào)函數(shù)繪制圖表
? ? ? // console.log('new: %s, old: %s', val, oldVal);
? ? ? // this.drawChart(val);
? ? // }
? methods: {
? ? drawChart() {
? ? ? // 2019.03.30 更新 destory方法已被廢棄
? ? ? // this.chart && this.chart.destory()
? ? ? this.chart = new G2.Chart({
? ? ? ? container: this.id,
? ? ? ? width: 1550,
? ? ? ? height: 425
? ? ? })
? ? ? this.chart.source(this.charData)
? ? ? this.chart.scale('value', {
? ? ? ? min: 0
? ? ? })
? ? ? this.chart.scale('year', {
? ? ? ? range: [0, 1]
? ? ? })
? ? ? this.chart.tooltip({
? ? ? ? crosshairs: {
? ? ? ? ? type: 'line'
? ? ? ? }
? ? ? })
? ? ? this.chart.line().position('year*value')
? ? ? this.chart.point().position('year*value').size(4).shape('circle').style({
? ? ? ? stroke: '#fff',
? ? ? ? lineWidth: 1
? ? ? })
? ? ? this.chart.render()
? ? }
? }
}
</script>
<style lang='less' scope>
? .gcharts{
? ? width:100%;
? ? height:100%;
? }
</style>

第三:調(diào)用部分

<lineCharts  :charData="lineData" :id="'chart1'"></lineCharts>
import lineCharts from '@/components/gcharts/lineCharts'//g2繪圖
components: {
    lineCharts,
  },
 
 
data () {
    return {
        lineData:[
                {year: '10/20',
                  value: 30
                }, {
                  year: '10/21',
                  value: 40
                }, {
                  year: '10/22',
                  value: 30.5
                }, {
                  year: '10/23',
                  value: 50
                }, {
                  year: '10/24',
                  value: 40.9
                }, {
                  year: '10/25',
                  value: 60
                }, {
                  year: '10/26',
                  value: 70
                }, {
                  year: '10/27',
                  value: 90
                }, {
                  year: '10/28',
                  value: 63
                }]
      
 
}}

antv g2柱狀圖與折線圖混合使用

這是數(shù)據(jù)

data: [
?{ time: '9:00-10:00', value: 30 , type: '曝光量', rate: 100 },
? ?{ time: '10:00-11:00', value: 90, type: '曝光量', rate: 200 },
? ?{ time: '11:00-12:00', value: 50, type: '點擊量', rate: 300 },
? ?{ time: '12:00-13:00', value: 30, type: '點擊量', rate: 400 },
? ?{ time: '13:00-14:00', value: 70, type: '點擊量', rate: 500 }
?],

這是組件 

<template>
? <div class="page">
? ? <div :id="id"></div>
? </div>
</template>
<script type="text/ecmascript-6">
import { Chart } from '@antv/g2';
export default {
? name: 'Name', // Pascal命名
? components: {},
? props: {
? ? id: {
? ? ? type: String,
? ? ? default: 'chart'
? ? },
? ? height: {
? ? ? type: Number,
? ? ? default: 500
? ? },
? ? chartWidth: {
? ? ? type: Number,
? ? },
? ? chartData: {
? ? ? type: Array,
? ? ? default: () => {}
? ? },
? },
? data() {
? ? return {};
? },
? computed: {},
? watch: {},
? filters: {},
? beforeCreate() {},
? created() {},
? mounted() {
? ? this.initPage();
? },
? methods: {
? ? initPage() {},
? ? drawChart() {
? ? ? const _this = this;
? ? ? const chart = new Chart({
? ? ? ? container: _this.id,
? ? ? ? autoFit: true,
? ? ? ? height: _this.height,
? ? ? ? width: _this.chartWidth
? ? ? });
? ? ? chart.data(_this.chartData);
? ? ? chart.scale({
? ? ? ? value: {
? ? ? ? ? alias: '銷售額(萬)',
? ? ? ? ? nice: true,
? ? ? ? },
? ? ? ? rate: {
? ? ? ? ? alias: '李大玄(百)',
? ? ? ? ? nice: true,
? ? ? ? },
? ? ? });
? ? ? chart.axis('rate', {
? ? ? ? title: {
? ? ? ? ? top: '0',
? ? ? ? ? style: {
? ? ? ? ? ? fill: 'green',
? ? ? ? ? },
? ? ? ? },
? ? ? });
? ? ? chart.axis('value', {
? ? ? ? title: {
? ? ? ? ? top: '0',
? ? ? ? ? style: {
? ? ? ? ? ? fill: 'green',
? ? ? ? ? },
? ? ? ? },
? ? ? });
? ? ??
? ? ? chart.tooltip({
? ? ? ? showCrosshairs: true, // 展示 Tooltip 輔助線
? ? ? ? showMarkers: false,
? ? ? ? shared: true,
? ? ? });
? ? ? chart.interaction('element-active');
? ? ? chart.legend({
? ? ? ? position: 'top',
? ? ? ? items: [
? ? ? ? ? { name: '曝光量', value: '曝光量', marker: { symbol: 'square', style: { fill: '#1890FF', r: 5 } } },
? ? ? ? ? { name: '點擊量', value: '點擊量', marker: { symbol: 'square', style: { fill: '#8c8c8c', r: 5 } } },
? ? ? ? ],
? ? ? });
? ? ??
? ? ? chart
? ? ? ? .interval()
? ? ? ? .adjust('stack')
? ? ? ? .color('type', ['red', 'pink'])
? ? ? ? .position('time*value')
? ? ? ? .style('time', val => {
? ? ? ? ? if (val === '13:00-14:00') {
? ? ? ? ? ? return {
? ? ? ? ? ? ? fillOpacity: 0.4,
? ? ? ? ? ? ? lineWidth: 1,
? ? ? ? ? ? ? stroke: '#636363',
? ? ? ? ? ? ? lineDash: [3, 2]
? ? ? ? ? ? };
? ? ? ? ? }
? ? ? ? ? return {
? ? ? ? ? ? fillOpacity: 1,
? ? ? ? ? ? lineWidth: 0,
? ? ? ? ? ? stroke: '#636363',
? ? ? ? ? ? lineDash: [100, 0.5]
? ? ? ? ? };
? ? ? ? });
? ? ? chart.line().position('time*rate').label('rate');
? ? ? chart.point().position('time*rate');
? ? ? // chart.interval().position('genre*sold');
? ? ? // chart.intervalDodge().position('date*value').color('type');
? ? ? chart.render();
? ? }
? },
};
</script>
<style lang="scss" scoped>
</style>

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳談vue+webpack解決css引用圖片打包后找不到資源文件的問題

    詳談vue+webpack解決css引用圖片打包后找不到資源文件的問題

    下面小編就為大家分享一篇詳談vue+webpack解決css引用圖片打包后找不到資源文件的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • Vant中List組件immediate-check=false無效的解決

    Vant中List組件immediate-check=false無效的解決

    這篇文章主要介紹了Vant中List組件immediate-check=false無效的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Vue3中多個彈窗同時出現(xiàn)的解決思路

    Vue3中多個彈窗同時出現(xiàn)的解決思路

    這篇文章主要介紹了Vue3中多個彈窗同時出現(xiàn)的解決思路,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • vue3獲取當(dāng)前路由地址

    vue3獲取當(dāng)前路由地址

    本文詳細講解了vue3獲取當(dāng)前路由地址的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01
  • 詳解vue渲染從后臺獲取的json數(shù)據(jù)

    詳解vue渲染從后臺獲取的json數(shù)據(jù)

    這篇文章主要介紹了詳解vue渲染從后臺獲取的json數(shù)據(jù),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 淺析前端路由簡介以及vue-router實現(xiàn)原理

    淺析前端路由簡介以及vue-router實現(xiàn)原理

    路由就是用來跟后端服務(wù)器進行交互的一種方式,通過不同的路徑,來請求不同的資源,請求不同的頁面是路由的其中一種功能。這篇文章主要介紹了前端路由簡介以及vue-router實現(xiàn)原理,需要的朋友可以參考下
    2018-06-06
  • vue中vue-router的使用說明(包括在ssr中的使用)

    vue中vue-router的使用說明(包括在ssr中的使用)

    這篇文章主要介紹了vue中vue-router的使用說明(包括在ssr中的使用),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • vue3中的reactive函數(shù)聲明數(shù)組方式

    vue3中的reactive函數(shù)聲明數(shù)組方式

    這篇文章主要介紹了vue3中的reactive函數(shù)聲明數(shù)組方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Vue源碼學(xué)習(xí)之關(guān)于對Array的數(shù)據(jù)偵聽實現(xiàn)

    Vue源碼學(xué)習(xí)之關(guān)于對Array的數(shù)據(jù)偵聽實現(xiàn)

    這篇文章主要介紹了Vue源碼學(xué)習(xí)之關(guān)于對Array的數(shù)據(jù)偵聽實現(xiàn),Vue使用了一個方式來實現(xiàn)Array類型的監(jiān)測就是攔截器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • vue中的生命周期及鉤子函數(shù)

    vue中的生命周期及鉤子函數(shù)

    這篇文章主要介紹了vue中的生命周期及鉤子函數(shù),Vue?實例有一個完整的生命周期,也就是從開始創(chuàng)建、初始化數(shù)據(jù)、編譯模板、掛載?Dom、渲染,下面文章詳細介紹,需要的朋友可以參考一下
    2021-12-12

最新評論

灵丘县| 天峨县| 平舆县| 孙吴县| 长乐市| 济南市| 达州市| 九龙城区| 龙游县| 阳高县| 通城县| 漳浦县| 巴林左旗| 鱼台县| 临漳县| 潼南县| 前郭尔| 车致| 瓦房店市| 太康县| 黄大仙区| 长治市| 四子王旗| 百色市| 万载县| 青铜峡市| 英山县| 历史| 华蓥市| 凤阳县| 福贡县| 徐水县| 卢氏县| 奉节县| 陕西省| 洞头县| 湘潭市| 靖边县| 巴彦淖尔市| 德庆县| 凭祥市|