Echarts柱狀圖導(dǎo)出圖片Vue

HTML


<div class="appealSignQuantityBox">? ? ? ? ? ?


? ? ? ? ? ? ? <button class="exportClass" @click="department_exportFigure">導(dǎo)出統(tǒng)計(jì)圖</button>

? ? ? ? ? ? <div class="AppealToStatisticsA e-box" id="AppealToStatisticsA"></div>

? ? ? ? </div>



JavaScript


import echarts from "echarts";

return{

}

getEchartsA(x,s,d,max) { //(名稱,統(tǒng)計(jì)1,統(tǒng)計(jì)2,最大值)

? ? ? let myChartA = echarts.init(document.getElementById("AppealToStatisticsA"));

? ? ? let option = {

? ? ? ? title: {

? ? ? ? ? // text: "按部門統(tǒng)計(jì)",

? ? ? ? ? textStyle: {

? ? ? ? ? ? fontSize: "16px",

? ? ? ? ? ? color: "#000"

? ? ? ? ? }

? ? ? ? },

? ? ? ? grid: {

? ? ? ? ? x: 50,

? ? ? ? ? y: 30,

? ? ? ? ? x2: 20,

? ? ? ? ? y2: 50,

? ? ? ? ? // y2: 65,

? ? ? ? },

? ? ? ? legend: {

? ? ? ? ? // orient: "vertical",

? ? ? ? ? // x: "right",

? ? ? ? },

? ? ? ? tooltip: {

? ? ? ? ? trigger: "axis",

? ? ? ? ? axisPointer: {

? ? ? ? ? ? type: "shadow"

? ? ? ? ? }

? ? ? ? },

? ? ? ? xAxis: {

? ? ? ? ? type: "category",

? ? ? ? ? ? data: x,

? ? ? ? ? axisTick: {

? ? ? ? ? ? alignWithLabel: true,

? ? ? ? ? ? boundaryGap: true,

? ? ? ? ? ? show: true

? ? ? ? ? ? // interval: 0,

? ? ? ? ? },

? ? ? ? ? axisLabel: {//強(qiáng)制顯示所有

? ? ? ? ? ? interval: 0,

? ? ? ? ? },

? ? ? ? ? // axisLabel: {

? ? ? ? ? //? rotate: 320,

? ? ? ? ? //? interval: 0

? ? ? ? ? // }

? ? ? ? },

? ? ? ? yAxis: [

? ? ? ? ? {

? ? ? ? ? ? type: "value",

? ? ? ? ? ? min: 0,

? ? ? ? ? ? // max: max,

? ? ? ? ? ? ?minInterval: 1,

? ? ? ? ? }

? ? ? ? ],

? ? ? ? series: [

? ? ? ? ? {

? ? ? ? ? ? name: "簽收統(tǒng)計(jì)",

? ? ? ? ? ? type: "bar",

? ? ? ? ? ? barGap: "30%",

? ? ? ? ? ? barWidth: "12",

? ? ? ? ? ? data: s

? ? ? ? ? },

? ? ? ? ? {

? ? ? ? ? ? name: "辦結(jié)統(tǒng)計(jì)",

? ? ? ? ? ? type: "bar",

? ? ? ? ? ? // barGap: "30%",

? ? ? ? ? ? barWidth: "12",

? ? ? ? ? ? data: d

? ? ? ? ? },

? ? ? ? ],

? ? ? };

? ? ? myChartA.setOption(option);

? ? ? //建議加上以下這一行代碼,不加的效果圖如下(當(dāng)瀏覽器窗口縮小的時(shí)候)

? ? ? window.addEventListener("resize", function() {

? ? ? ? myChartA.resize();

? ? ? });

? ? },

department_exportFigure(){

? ? ? ? let mycanvas = $("#AppealToStatisticsA").find("canvas")[0];

? ? ? ? let image = mycanvas.toDataURL("image/png");

? ? ? ? let $a = document.createElement('a');

? ? ? ? $a.setAttribute("href", image);

? ? ? ? $a.setAttribute("download", "");

? ? ? ? $a.click();

? ? ? ? $a.setAttribute("download", "echarts圖片下載");

? ? },


CSS


.exportClass {

? ? ? ? float: right;

? ? ? ? height: 28px;

? ? ? ? color: #fff;

? ? ? ? margin-left: 5px;

? ? ? ? border-radius: 5px;

? ? ? ? padding: 0px 10px;

? ? ? ? background-color: #169bd5;

? ? }



個(gè)人覺得很簡(jiǎn)單? 如果不懂請(qǐng)留言 , 看到了就會(huì)回哈 !

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容