Skip to content

Instantly share code, notes, and snippets.

@llccing
Created July 26, 2017 10:52
Show Gist options
  • Save llccing/38df0dcf3db543556b3a1a0108f7f1dc to your computer and use it in GitHub Desktop.
Save llccing/38df0dcf3db543556b3a1a0108f7f1dc to your computer and use it in GitHub Desktop.
deal message
function filterDataByMonth(data) {
// 得到按时间排序的数据
var numArr = data.map(function (crtVal, idx, arr) {
return {
amount: crtVal.amount,
month: parseInt(crtVal.month)
}
}).sort(function (a, b) {
return a.month - b.month;
});
// X轴的值
var xAxisData = [];
// 柱形图的值
var barData = [];
// 折线图的值
var lineData = [];
// 最大值
var max = '';
numArr.forEach(function (crtVal, idx, arr) {
if (crtVal.month.length > 2) {
xAxisData.push(crtVal.month + '年');
} else {
xAxisData.push(crtVal.month + '月');
}
barData.push(crtVal.amount);
lineData.push(crtVal.amount);
});
var max = Math.max.apply(Math, barData); // 3
var yAxisMax = max + max / 5;
var interval = max / 5;
return {
legend: ['清洗', '对比'],
xAxisData: xAxisData,
yAxis: [
{
type: 'value',
name: '数量',
min: 0,
max: yAxisMax,
interval: interval,
axisLabel: {
formatter: '{value}'
}
}
],
seriesData: {
barData: barData,
lineData: lineData
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment