php echarts各种图表,常用的echarts图表的实现代码

本篇文章给大家带来的内容是关于常用的echarts图表的实现代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

本文代码基于ehcarts4.0开发

饼图

b3b8c1c64bb3ab94037510f9020b0c5a.png// 饼图配置项

var option = {

series: [

{

name:'风险预警占比',

type: 'pie',

radius: ['25%', '40%'],

center: ['50%', '50%'],

roseType: false,

data: [

{

value: 40,

name: '红色预警'

}, {

value: 30,

name: '橙色预警'

}, {

value: 10,

name: '黄色预警'

}, {

value: 50,

name: '蓝色预警'

}

],

label: {

fontSize: 12,

color:'#545454',

formatter: function (param) {

return param.name + '(' + Math.round(param.percent) + '%' + ')'

+ '\n' + param.value + '个';

}

},

labelLine: {

smooth: false,

lineStyle: {

width: 2

}

},

itemStyle: {

color:function(params){

switch (params.name) {

case '红色预警':

return '#D70002';

case '橙色预警':

return '#FF9309';

case '黄色预警':

return '#FFFB09';

case '蓝色预警':

return '#035EF7';

default:

break;

}

}

},

}

]

}

堆叠柱状图

e108052d7a3b411e42bbef002f5a9dd5.png//堆叠柱状图配置项

var option = {

backgroundColor: '#fff',

tooltip: {

trigger: 'axis',

axisPointer: {

type: 'shadow'

}

},

legend: {

bottom: '10',

itemGap: 30,

data: ['一级', '二级', '三级', '四级']

},

grid: { //图表的位置

top: 30,

left: 10,

right: 80,

bottom: 60,

containLabel: true

},

dataZoom: [

{

type: 'inside'

}, {

type: 'slider',

start: 0,

bottom: 40,

height: '15px',

fillerColor:'rgba(202,223,255,.8)',

borderColor:'#b6d2fc',

handleStyle:{

color:'#b6d2fc'

},

dataBackground:{

lineStyle:{

color:'#b6d2fc'

},

areaStyle:{

color:'rgba(202,223,255,.8)'

}

}

}

],

yAxis: [

{

type: 'value',

name: '备案个数',

nameTextStyle: {

fontSize: 12,

fontWeight: 'bold',

color: '#454545'

},

splitLine: {

show: false

},

axisLine: {

lineStyle: {

color: '#B3B3B3'

}

},

axisLabel: {

color: '#454545'

}

}

],

xAxis: [

{

type: 'category',

name: '区县名称',

nameTextStyle: {

fontSize: 12,

fontWeight: 'bold',

color: '#454545'

},

axisLine: {

lineStyle: {

color: '#B3B3B3'

}

},

axisLabel: {

color: '#454545'

},

data: ['鼓楼区','玄武区','秦淮区']

}

],

series: [

{

name: '一级',

type: 'bar',

stack: '总量',

barWidth: '10px',

itemStyle:{

color:'#D70002'

},

data: [2,4,6]

},

{

name: '二级',

type: 'bar',

stack: '总量',

barWidth: '10px',

data: [2,4,1]

},

{

name: '三级',

type: 'bar',

stack: '总量',

barWidth: '10px',

itemStyle:{

color:'#FFFB09'

},

data: [1,5,7]

},

{

name: '四级',

type: 'bar',

stack: '总量',

barWidth: '10px',

itemStyle:{

color:'#FF9309'

},

data: [1]

}

]

}

渐变柱状图

0748363a70fae1c700318fe5fa034ff1.png//配置项

var option = {

backgroundColor: '#fff',

color: [

new echarts.graphic.LinearGradient(

0, 0, 0, 1,

[

{ offset: 0, color: '#23E9EE' },

{ offset: 1, color: '#0460F7' }

]

)

],

tooltip: {

trigger: 'axis',

axisPointer: {

type: 'shadow'

}

},

legend: {

bottom: '10',

itemGap: 30,

data: ['一级', '二级', '三级', '四级']

},

grid: { //图表的位置

top: 30,

left: 10,

right: 80,

bottom: 60,

containLabel: true

},

dataZoom: [

{

type: 'inside'

}, {

type: 'slider',

start: 0,

bottom: 40,

height: '15px',

fillerColor:'rgba(202,223,255,.8)',

borderColor:'#b6d2fc',

handleStyle:{

color:'#b6d2fc'

},

dataBackground:{

lineStyle:{

color:'#b6d2fc'

},

areaStyle:{

color:'rgba(202,223,255,.8)'

}

}

}

],

yAxis: [

{

type: 'value',

name: '备案个数',

nameTextStyle: {

fontSize: 12,

fontWeight: 'bold',

color: '#454545'

},

splitLine: {

show: false

},

axisLine: {

lineStyle: {

color: '#B3B3B3'

}

},

axisLabel: {

color: '#454545'

}

}

],

xAxis: [

{

type: 'category',

name: '区县名称',

nameTextStyle: {

fontSize: 12,

fontWeight: 'bold',

color: '#454545'

},

axisLine: {

lineStyle: {

color: '#B3B3B3'

}

},

axisLabel: {

color: '#454545'

},

data: ['鼓楼区','玄武区','秦淮区']

}

],

series: [

{

name: '报警',

type: 'bar',

stack: '总量',

barWidth: '10px',

data: [1,2,4]

}

]

};

线图

10b13b85767265c76e69168cb9e0563e.png//线图配置项

var option = {

tooltip: {

trigger: 'axis'

},

color: [

new echarts.graphic.LinearGradient(

0, 0, 0, 1,

[

{offset: 0, color: '#23E9EE'},

{offset: 1, color: '#0460F7'}

]

)

],

grid: {

top: 30,

left: 10,

right: 30,

bottom: 50,

containLabel: true

},

dataZoom: [

{

type: 'inside'

}, {

type: 'slider',

start: 0,

bottom: 30,

height: '15px',

fillerColor:'rgba(202,223,255,.8)',

borderColor:'#b6d2fc',

handleStyle:{

color:'#b6d2fc'

},

dataBackground:{

lineStyle:{

color:'#b6d2fc'

},

areaStyle:{

color:'rgba(202,223,255,.8)'

}

}

}

],

yAxis: [

{

type: 'value',

splitLine: {

show: false

},

axisLine: {

lineStyle: {

color: '#B3B3B3'

}

},

axisLabel: {

color: '#454545'

}

}

],

xAxis: {

type: 'category',

boundaryGap:false,

axisLine: {

lineStyle: {

color: '#B3B3B3'

}

},

axisLabel: {

color: '#454545'

},

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

},

series: [

{

name: '报警个数',

type: 'line',

symbol: 'emptyCircle',

symbolSize: 2,

showSymbol: false,

smooth: true,

areaStyle: {

color: new echarts.graphic.LinearGradient(

0, 0, 0, 1,

[

{offset: 0, color: 'rgba(35,233,238,.4)'},

{offset: 1, color: 'rgba(4,96,247,.4)'}

]

)

},

lineStyle: {

width: 1,

color: '#59cef5'

},

itemStyle: {

borderColor: '#59cef5',

borderWidth: 2

},

data:[2,4,3,2,1,4,2]

}

]

}

创建实例var chart = echarts.init(document.getElementById('chartBox'));

设置图表实例的配置项设置图表实例的配置项以及数据,万能接口,所有参数和数据的修改都可以通过setOption完成,ECharts 会合并新的参数和数据,然后刷新图表chart.setOption(option);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您可以按照以下步骤来实现: 1. 首先,在您的PHP代码中连接到MySQL数据库,使用PHP的mysqli或PDO扩展来执行查询语句,获取您需要的数据。 2. 将这些数据格式化为您想要的JSON格式,以便在echarts中使用。 3. 在您的HTML文件中引入echarts库,并创建一个具有合适配置的div容器。 4. 使用JavaScript将您的JSON数据传递给echarts实例,并使用其提供的API来创建地图图表。 下面是一个简单的示例代码,可以帮助您开始: PHP代码: ``` //连接到MySQL数据库 $conn = new mysqli($servername, $username, $password, $dbname); //执行查询语句 $sql = "SELECT province, value FROM your_table"; $result = $conn->query($sql); //格式化数据为JSON格式 $data = array(); while($row = $result->fetch_assoc()) { $data[] = array( 'name' => $row['province'], 'value' => $row['value'] ); } $json_data = json_encode($data); ``` HTML代码: ``` <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Map Chart</title> <!-- 引入echarts库 --> <script src="https://cdn.jsdelivr.net/npm/echarts@5.1.1/dist/echarts.min.js"></script> </head> <body> <!-- 创建容器 --> <div id="map" style="width: 800px; height: 600px;"></div> <script> //使用JSON数据创建地图图表 var myChart = echarts.init(document.getElementById('map')); var option = { title: { text: 'Map Chart' }, tooltip: { trigger: 'item' }, series: [{ type: 'map', map: 'china', data: <?php echo $json_data; ?> }] }; myChart.setOption(option); </script> </body> </html> ``` 请注意,这只是一个简单的示例,您可能需要根据您的数据和需求进行更改和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值