6

ECharts 时间横坐标自动计算

```series: [
{
"name": "销量",
"type": "line",
"data": [5, 20, 40, 10, 10, 20, 20, 40, 10, 10, 25, 20, 40, 10, 10, 25, 20]
}```

LsHao

引用来自“zhonghai”的评论

axis.axisLabel formatter 能满足你的需求吗

```var option1 = {
tooltip: {
show: true
},
legend: {
data: ['销量']
},
xAxis: [
{
// type: 'time',
//name: '时间',
// splitNumber:24*3600,
//min: (new Date()).setDate(1),
//scale:true,
//splitNumber:14,
//max:new Date(),
//boundaryGap: false,
//data: []
//data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
"name": "销量",
"type": "line",
"data": [5, 20, 40, 10, 10, 20, 20, 40, 10, 10, 25, 20, 40, 10, 10, 25, 20]
}
]
};```

引用来自“zhonghai”的评论

“根据数据自动计算横坐标”,你能给出这些数据是什么样的吗

series: [

{
"name":"销量",
"type":"line",
"data": [5, 20, 40, 10, 10, 20, 20, 40, 10, 10, 25, 20, 40, 10, 10, 25, 20]
}
]

var beginDt = new Date('2015-01-01');
var data =  [5, 20, 40, 10, 10, 20, 20, 40, 10, 10, 25, 20, 40, 10, 10, 25, 20];
echartsDate  = [];
for(var i=0;i<data.length;i++){
var d = beginDt.getFullYear() + "-" + (beginDt.getMonth() + 1) + "-" + beginDt.getDate();
echartsDate.push(d);
beginDt.setDate(beginDt.getDate() + 1)
}

option = {
tooltip: {
show: true
},
legend: {
data: ['销量']
},
xAxis: [
{
name:'sss',
data:echartsDate
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
"name": "销量",
"type": "line",
"data":data
}
]
};