php display 带参数,display.php

本文通过ECharts实现了一次多维度的数据可视化展示,包括文本、图片、新增用户和粉丝数量的统计。利用Ajax从PHP接口获取JSON数据,分别绘制了四条折线图,并使用渐变颜色填充区域,增强了图表的视觉效果。同时,文章还展示了如何处理异步数据加载和ECharts配置选项,为数据监控和分析提供了实用的示例。
摘要由CSDN通过智能技术生成
ECharts

var myChart = echarts.init(document.getElementById('main'));

/*变量*/

var date =[];//日期时间

var dates = [];

var date3=[];

var date4=[];//数据

var data = [];

var data2 = [];

var data3 = [];

var data4 =[];

var total ;

function getusers() {//text_total文本数据统计

$.ajax({

type: "GET",

url: "t_total.php",

data: {},

dataType: "json",

success: function(result){

console.log(result)

if(result){

console.log("error");

for(var i = 0 ; i < result.length; i++){

date.push(result[i].date);

data.push(result[i].count);

}

}

},

error: function(errmsg) {

// console.log("error",errmsg)

alert("Ajax获取服务器数据出错了!"+ errmsg);

}

});

return date,data;

}

function getusers2() {//image_total图片数据统计

$.ajax({

type: "GET",

url: "i_total.php",

data: {},

dataType: "json",

success: function(result){

console.log(result)

if(result){

console.log("error");

for(var i = 0 ; i < result.length; i++){

dates.push(result[i].date);

data2.push(result[i].count);

}

}

},

error: function(errmsg) {

// console.log("error",errmsg)

alert("Ajax获取服务器数据出错了!"+ errmsg);

}

});

return dates,data2;

}

function getusers3() {//content_total入群数据统计

$.ajax({

type: "GET",

url: "c_total.php",

data: {},

dataType: "json",

success: function(result){

console.log(result)

if(result){

console.log("error");

for(var i = 0 ; i < result.length; i++){

date3.push(result[i].date);

data3.push(result[i].count);

}

}

},

error: function(errmsg) {

// console.log("error",errmsg)

alert("Ajax获取服务器数据出错了!"+ errmsg);

}

});

return date3,data3;

}

function getusers4() {//person_total个人粉丝数据统计

$.ajax({

type: "GET",

url: "p_total.php",

data: {},

dataType: "json",

success: function(result){

console.log(result)

if(result){

console.log("error");

for(var i = 0 ; i < result.length; i++){

date4.push(result[i].date);

data4.push(result[i].count);

}

}

},

error: function(errmsg) {

// console.log("error",errmsg)

alert("Ajax获取服务器数据出错了!"+ errmsg);

}

});

return date4,data4;

}

getusers();//text_total文本数据统计

getusers2();//image_total图片数据统计

getusers3();//content_total入群数据统计

getusers4();//person_total个人粉丝数据统计

/*接收处理的多条数据*/

function fetchData(cb) {

// 通过 setTimeout 模拟异步加载

setTimeout(function() {

cb({

categories: date,

data: data,

data2: data2,

data3: data3,

data4: data4

});

}, 1000);

}

/*Echart显示*/

var myChart = echarts.init(document.getElementById('main'));

option = {

backgroundColor: '#394056',

title: {

text: '数量',

textStyle: {

fontWeight: 'normal',

fontSize: 16,

color: '#F1F1F3'

},

left: '6%'

},

tooltip: {

trigger: 'axis',

axisPointer: {

lineStyle: {

color: '#57617B'

}

}

},

legend: {

icon: 'rect',

itemWidth: 14,

itemHeight: 5,

itemGap: 13,

data: ['文本', '图片', '新增','粉丝'],

right: '4%',

textStyle: {

fontSize: 12,

color: '#F1F1F3'

}

},

grid: {

left: '3%',

right: '4%',

bottom: '3%',

containLabel: true

},

xAxis: [{

type: 'category',

boundaryGap: false,

axisLine: {

lineStyle: {

color: '#57617B'

}

},

axisLabel :{

interval:0

},

data: []

}],

yAxis: [{

type: 'value',

axisTick: {

show: false

},

axisLine: {

lineStyle: {

color: '#57617B'

}

},

axisLabel: {

margin: 10,

textStyle: {

fontSize: 14

}

},

splitLine: {

lineStyle: {

color: '#57617B'

}

}

}],

series: [{

name: '文本',

type: 'line',

smooth: true,

symbol: 'circle',

symbolSize: 5,

showSymbol: false,

lineStyle: {

normal: {

width: 1

}

},

areaStyle: {

normal: {

color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{

offset: 0,

color: 'rgba(137, 189, 27, 0.3)'

}, {

offset: 0.8,

color: 'rgba(137, 189, 27, 0)'

}], false),

shadowColor: 'rgba(0, 0, 0, 0.1)',

shadowBlur: 10

}

},

itemStyle: {

normal: {

color: 'rgb(137,189,27)',

borderColor: 'rgba(137,189,2,0.27)',

borderWidth: 12

}

},

data: []

}, {

name: '图片',

type: 'line',

smooth: true,

symbol: 'circle',

symbolSize: 5,

showSymbol: false,

lineStyle: {

normal: {

width: 1

}

},

areaStyle: {

normal: {

color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{

offset: 0,

color: 'rgba(0, 136, 212, 0.3)'

}, {

offset: 0.8,

color: 'rgba(0, 136, 212, 0)'

}], false),

shadowColor: 'rgba(0, 0, 0, 0.1)',

shadowBlur: 10

}

},

itemStyle: {

normal: {

color: 'rgb(0,136,212)',

borderColor: 'rgba(0,136,212,0.2)',

borderWidth: 12

}

},

data: []

}, {

name: '新增',

type: 'line',

smooth: true,

symbol: 'circle',

symbolSize: 5,

showSymbol: false,

lineStyle: {

normal: {

width: 1

}

},

areaStyle: {

normal: {

color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{

offset: 0,

color: 'rgba(219, 50, 51, 0.3)'

}, {

offset: 0.8,

color: 'rgba(219, 50, 51, 0)'

}], false),

shadowColor: 'rgba(0, 0, 0, 0.1)',

shadowBlur: 10

}

},

itemStyle: {

normal: {

color: 'rgb(219,50,51)',

borderColor: 'rgba(219,50,51,0.2)',

borderWidth: 12

}

},

data: []

}, {

name: '粉丝',

type: 'line',

smooth: true,

symbol: 'circle',

symbolSize: 5,

showSymbol: false,

lineStyle: {

normal: {

width: 1

}

},

areaStyle: {

normal: {

color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{

offset: 0,

color: 'rgba(199, 237, 250,0.5)'

}, {

offset: 1,

color: 'rgba(199, 237, 250,0.2)'

}], false),

shadowColor: 'rgba(0, 0, 0, 0.1)',

shadowBlur: 10

}

},

itemStyle: {

normal: {

color: 'rgb(199, 237, 250)',

borderColor: 'rgba(199, 237, 250,0.2)',

borderWidth: 12

}

},

data: []

}]

};

myChart.showLoading();

fetchData(function(data) {

myChart.hideLoading();

myChart.setOption({

xAxis: {

data: data.categories

},

series: [{

// 根据名字对应到相应的系列

name: '文本',

data: data.data

},

{

// 根据名字对应到相应的系列

name: '图片',

data: data.data2

},

{

// 根据名字对应到相应的系列

name: '新增',

data: data.data3

},

{

// 根据名字对应到相应的系列

name: '粉丝',

data: data.data4

}

]

});

});

myChart.setOption(option);

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值