首页 分享 Echarts 图表插件学习(2)

Echarts 图表插件学习(2)

来源:花匠小妙招 时间:2025-01-11 22:33

自定义导出:

工具栏导出:

上代码:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>ECharts</title>

</head>

<body>

<div id="main" style="height:400px;width: 700px"></div>

<p></p>

<p></p>

<p></p>

<p></p>

<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>

<script type="text/javascript">

var myChart = "";

require.config({

paths: {

echarts: 'http://echarts.baidu.com/build/dist'

}

});

require(

[

'echarts',

'echarts/chart/bar'

],

function (ec) {

myChart = ec.init(document.getElementById('main'));

var option = {

tooltip: {

show: true

},

legend: {

data:['销量']

},

xAxis : [

{

type : 'category',

data : ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]

}

],

yAxis : [

{

type : 'value'

}

],

series : [

{

"name":"销量",

"type":"bar",

"data":[5, 20, 40, 10, 10, 20]

}

]

};

myChart.setOption(option);

setTimeout(function() {

var img = new Image();

img.src = myChart.getDataURL({

type:"png",

pixelRatio: 2,

backgroundColor: '#fff'

});

img.onload=function(){

var canvas=document.createElement("canvas");

canvas.width=img.width;

canvas.height=img.height;

var ctx=canvas.getContext('2d');

ctx.drawImage(img,0,0);

var dataURL=canvas.toDataURL('image/png');

var a = document.createElement('a');

var event = new MouseEvent('click');

a.download = '矩形图表.png' || '下载图片名称';

a.href = dataURL;

a.dispatchEvent(event);

};

}, 1000)

}

);

</script>

<div id="main2" style="height:400px;width: 700px"></div>

<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>

<script type="text/javascript">

require.config({

paths: {

echarts: 'http://echarts.baidu.com/build/dist'

}

});

require(

[

'echarts',

'echarts/chart/line'

],

function (ec) {

var myChart = ec.init(document.getElementById('main2'));

var option1 = {

title : {

text: '未来一周气温变化',

subtext: '纯属虚构'

},

tooltip : {

trigger: 'axis'

},

legend: {

data:['最高气温','最低气温','深圳气温']

},

grid:{

containLabel:true

},

calculable : true,

toolbox: {

show : true,

feature : {

mark : {show: true},

dataView : {show: true, readOnly: false},

magicType : {show: true, type: ['line', 'bar']},

restore : {show: true},

saveAsImage : {show: true}

}

},

xAxis : [

{

type : 'category',

boundaryGap : false,

data : ['周一','周二','周三','周四','周五','周六','周日']

}

],

yAxis : [

{

type : 'value',

axisLabel : {

formatter: '{value} °C'

}

}

],

series : [

{

name:'最高气温',

type:'line',

data:[11, 11, 15, 13, 12, 13, 10],

},

{

name:'最低气温',

type:'line',

data:[1, -2, 2, 50000000, 3, 2, 0],

},

{

name:'深圳气温',

type:'line',

data:[6, -2, 3, 5, 3, 2, 14],

}

]

};

myChart.setOption(option1);

}

);

</script>

</body>

</html>

相关知识

常用大数据可视化分析工具介绍
基于Echarts的鸢尾花数据可视化
屏幕适配方案——详细完整版
基于Python的全国主要城市天气数据可视化大屏系统
vue3 + VIte + TS 移动端 H5 项目屏幕适配,PC端响应式布局
C4D常用14款插件
在线制作树形图
3DS MAX插件
C4D插件大全,C4D插件怎么安装,C4D插件怎么使用(含C4D如何使用教程)
微信小程序插件

网址: Echarts 图表插件学习(2) https://www.huajiangbk.com/newsview1545032.html

所属分类:花卉
上一篇: 4.1. Matplotlib
下一篇: 【Unity 实用工具篇】✨

推荐分享