前端要求格式:
data: [
{ value: 1048, name: 'Search Engine'},
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads'},
{ value: 300, name: 'Video Ads'}
]
展示效果:
后端处理:
java
class DataPoint {
private int value;
private String name;
public DataPoint(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "{ value: " + value + ", name: '" + name + "' }";
}
}
public class Main {
public static void main(String[] args) {
List<DataPoint> dataList = new ArrayList<>();
dataList.add(new DataPoint(1048, "Search Engine"));
dataList.add(new DataPoint(735, "Direct"));
dataList.add(new DataPoint(580, "Email"));
dataList.add(new DataPoint(484, "Union Ads"));
dataList.add(new DataPoint(300, "Video Ads"));
// 输出数据
for (DataPoint dataPoint : dataList) {
System.out.println(dataPoint);
}
}
}