Vue+Antv?F2實(shí)現(xiàn)層疊柱狀圖
本文實(shí)例為大家分享了Vue+ Antv F2實(shí)現(xiàn)層疊柱狀圖的具體代碼,供大家參考,具體內(nèi)容如下
一、 創(chuàng)建canvas標(biāo)簽
<canvas id="caseChart" style="width: 100%;height: 230px;"></canvas>
二、 編寫圖表繪制代碼
methods:{
?? ? ? ?//獲取專利案件Chart圖標(biāo)信息
?? ? ? ?getCaseChartData(){
?? ? ? ??? ?var _this = this;
?? ? ? ??? ?var params = {
?? ? ? ??? ??? ?dataType:_this.caseDataType,
?? ??? ??? ??? ?beginDate:'',
?? ??? ??? ??? ?endDate:_this.endDate
?? ? ? ??? ?}?? ??? ? ? ??? ?
?? ? ? ??? ?_this.$http.get('/api/patent/StatisticsPatentChartAmount',{params:params})
?? ? ? ??? ?.then(res =>{
?? ? ? ??? ??? ?if(res.status == 200){
?? ? ? ??? ??? ??? ?for(var i = 0; i < res.data.length; i++){
?? ? ? ??? ??? ??? ??? ?if(res.data[i].dataType == "monthPatent"){res.data[i].dataType = '新立案'}
?? ? ? ??? ??? ??? ??? ?else if(res.data[i].dataType == "applyPatent"){res.data[i].dataType = '新申請(qǐng)'}
?? ? ? ??? ??? ??? ??? ?else if(res.data[i].dataType == "PCTPatent"){res.data[i].dataType = 'PCT國際'}
?? ? ? ??? ??? ??? ??? ?else if(res.data[i].dataType == "otherPatent"){res.data[i].dataType = '其他案件'}
?? ? ? ??? ??? ??? ??? ?else {}
?? ? ? ??? ??? ??? ??? ?res.data[i].date = res.data[i].date+"-01" + " 00:00:00"
?? ? ? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?_this.caseData = res.data;
?? ??? ??? ??? ??? ?_this.$options.methods.caseChart.bind(this)();
?? ? ? ??? ??? ?}else{
?? ? ? ??? ??? ??? ?
?? ? ? ??? ??? ?}
?? ??? ??? ?})
?? ? ? ??? ?.catch(error =>{
?? ??? ??? ?})?? ??? ??? ? ? ??? ?
?? ? ? ?},
?? ?
?? ??? ?caseChart(){
?? ??? ??? ?var _this = this;
?? ??? ??? ?//創(chuàng)建 Chart 對(duì)象
?? ??? ??? ?_this.casechart = new this.$F2.Chart({?? ??? ??? ?
?? ??? ??? ? ?id: 'caseChart',
?? ??? ??? ? ?pixelRatio: window.devicePixelRatio,?? ??? ??? ?//指定分辨率
?? ??? ??? ?});
?? ??? ??? ?//source 載入數(shù)據(jù)
?? ??? ??? ?_this.casechart.source(JSON.parse(JSON.stringify(this.caseData)), {?? ?
?? ??? ??? ? ?date: {?? ?//x軸
?? ??? ??? ? ? ?type: 'timeCat',
?? ??? ??? ? ? ?tickCount: 6,
?? ?//?? ??? ??? ?range: [ 0.1, 0.9 ],
?? ??? ??? ? ? ?mask:'YY-MM',
?? ??? ??? ? ?},
//?? ??? ??? ? ?amount: {?? ?
//?? ??? ??? ? ?}
?? ??? ??? ?});
?? ??? ??? ?_this.casechart.tooltip({
?? ??? ??? ? ?custom: true, // 自定義 tooltip 內(nèi)容框
?? ??? ??? ? ?onChange: function onChange(obj) {
?? ??? ??? ? ? ?const legend = _this.casechart.get('legendController').legends.top[0];
?? ??? ??? ? ? ?const tooltipItems = obj.items;
?? ??? ??? ? ? ?const legendItems = legend.items;
?? ??? ??? ? ? ?const map = {};
?? ??? ??? ? ? ?legendItems.forEach(function(item) {
?? ??? ??? ? ? ? ?map[item.name] = item;
?? ??? ??? ? ? ?});
?? ??? ??? ? ? ?tooltipItems.forEach(function(item) {
?? ??? ??? ? ? ? ?const name = item.name;
?? ??? ??? ? ? ? ?const value = item.value;
?? ??? ??? ? ? ? ?if (map[name]) {
?? ??? ??? ? ? ? ? ?map[name].value = value;
?? ??? ??? ? ? ? ?}
?? ??? ??? ? ? ?});
?? ?//?? ??? ??? ?legend.setItems(_.values(map));
?? ??? ??? ? ?},
?? ??? ??? ? ?onHide: function onHide() {
?? ??? ??? ? ? ?const legend = _this.casechart.get('legendController').legends.top[0];
?? ??? ??? ? ? ?legend.setItems(_this.casechart.getLegendItems().country);
?? ??? ??? ? ?}
?? ??? ??? ?});?? ?
?? ??? ??? ?
?? ??? ??? ?var barWidth = 16 * (window.innerWidth / 375);
?? ??? ??? ?
?? ??? ??? ?//創(chuàng)建圖形語法,繪制圖,由 date 和 amount 兩個(gè)屬性決定圖形位置,date 映射至 x 軸,amount 映射至 y 軸
?? ??? ??? ?_this.casechart.interval()?? ??? ??? ?
?? ??? ??? ? ?.position('date*amount')
?? ??? ??? ? ?.color('dataType')
?? ??? ??? ? ?.adjust('stack')
?? ??? ??? ? ?.size(barWidth)
?? ??? ??? ?//渲染圖表
?? ??? ??? ?_this.casechart.render();?? ??? ??? ??? ?
?? ??? ?}
?? ?},
?? ?mounted() {
?? ??? ?var v = this;
?? ??? ?this.$nextTick(() => {
?? ??? ??? ?v.caseChart();
?? ??? ?});
?? ?},三、展示效果

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
淺談Vue static 靜態(tài)資源路徑 和 style問題
這篇文章主要介紹了淺談Vue static 靜態(tài)資源路徑 和 style問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-11-11
在Vue3中實(shí)現(xiàn)拖拽文件上傳功能的過程詳解
文件上傳是我們?cè)陂_發(fā)Web應(yīng)用時(shí)經(jīng)常遇到的功能之一,為了提升用戶體驗(yàn),我們可以利用HTML5的拖放API來實(shí)現(xiàn)拖拽文件上傳的功能,本文將介紹如何在Vue3中實(shí)現(xiàn)這一功能,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下2023-12-12
前端vue3使用axios調(diào)用后端接口的實(shí)現(xiàn)方法
vue本身不支持ajax接口的請(qǐng)求,所以在vue中經(jīng)常使用axios這個(gè)接口請(qǐng)求工具,下面這篇文章主要給大家介紹了關(guān)于前端vue3使用axios調(diào)用后端接口的實(shí)現(xiàn)方法,需要的朋友可以參考下2022-12-12
vue刷新子組件、重置組件以及重新加載子組件項(xiàng)目實(shí)戰(zhàn)記錄
在vue開發(fā)中出于各種目的,我們常常需要讓組件重新加載渲染,這篇文章主要給大家介紹了關(guān)于vue刷新子組件、重置組件以及重新加載子組件的相關(guān)資料,需要的朋友可以參考下2023-12-12
Vue.js的動(dòng)態(tài)組件模板的實(shí)現(xiàn)
這篇文章主要介紹了Vue.js的動(dòng)態(tài)組件模板的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11
詳解Vue2+Echarts實(shí)現(xiàn)多種圖表數(shù)據(jù)可視化Dashboard(附源碼)
本篇文章主要介紹了詳解Vue2+Echarts實(shí)現(xiàn)多種圖表數(shù)據(jù)可視化Dashboard(附源碼),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
element?table?表格控件實(shí)現(xiàn)單選功能
本文主要介紹了element?table?表格控件實(shí)現(xiàn)單選功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07

