0
谢谢大家回答我的不成熟的问题问最后一次,但是,我仍然无法弄清楚如何处理[X,Y]系列数据。
它工作正常时数据是一个整数的单个数组,但一个结构数组不工作。我该如何解决它?
series: [{//should work like this
data: [
["1", 29.9],
["2", 71.5],
["3", 106.4]
]
}]
type Line struct {//my struct
Data []Point `json:"data"` //this is the tricky part
}
type Point struct {
Date string
Value int
}
<script>
$(document).ready(function() {
var options = {
chart: {
renderTo: 'ERP_Chart',
type: 'spline'
},
series: []
};
$.getJSON("/Get_ERP_Chart", function(data) {
options.series = data;
var chart = new Highcharts.Chart(options);
});
});
</script>
我的服务器端运行的代码
type Line struct {
Data []Point `json:"data"` //this is the tricky part...
}
type Point struct {
Date string
Value int
}
func showERPChart(writer http.ResponseWriter, request *http.Request) {
var profit, expense, contacts Line
var chart []Line
rows, err := Db.Query("SELECT profit,expense,contacts,_date FROM Sells ORDER BY _date")
var prof, exp, con int
var date string
for rows.Next() {
err = rows.Scan(&prof, &exp, &con, &date)
profit.Data = append(profit.Data, Point{date, prof})
expense.Data = append(expense.Data, Point{date, exp})
contacts.Data = append(contacts.Data, Point{date, con})
}
chart = append(chart, profit)
chart = append(chart, expense)
chart = append(chart, contacts)
js, _:= json.Marshal(chart)
writer.Write(js)
}
请输出您的字段名称,即将'name string'更改为'Name string'等。 – mkopriva