我是图表和图形的新手,看来这并没有变得更容易。
我正在使用AnyChart
图表,但json
它嵌入在html
. 我想将其分开,以便从MyFile.json中读取。
这是呈现图表的javascript。这很好用:
anychart.onDocumentReady(function() {
var dataTable = anychart.data.table("Date", "dd/MM/yyyy");
dataTable.addData([
{"Date":"01/01/2017","Cars":12,"Bikes":143,"Trucks":7},
{"Date":"01/02/2017","Cars":30,"Bikes":171,"Trucks":3},
{"Date":"01/03/2017","Cars":50,"Bikes":157,"Trucks":9},
{"Date":"01/04/2017","Cars":26,"Bikes":194,"Trucks":2},
{"Date":"01/05/2017","Cars":15,"Bikes":192,"Trucks":8}
]);
var mapping1 = dataTable.mapAs({'value': "Cars"});
var mapping2 = dataTable.mapAs({'value': "Bikes"});
var mapping3 = dataTable.mapAs({'value': "Trucks"});
chart = anychart.stock();
var plot = chart.plot();
scale1 = anychart.scales.linear();
scale1.maximum(10);
plot.yAxis(1).enabled(true);
plot.yAxis(1).orientation("right");
plot.yAxis(1).scale("right");
line1 = plot.line(mapping1).name("Cars");
line2 = plot.line(mapping2).name("Bikes");
column = plot.column(mapping3).name("Trucks");
column.yScale(scale1);
plot.yAxis(1).stroke(column.color()).ticks().stroke(column.color());
chart.scroller().line(mapping1);
chart.title("Use mouse to draw zoom marquee");
chart.container("container").draw();
chart.startZoomMarquee(true, false);
chart.listen("dblclick", function(){
chart.selectRange("max");
});
});
按照此链接,我尝试了此操作,但出现错误SyntaxError: missing ) after argument list
/AnyChart/index.html:71
:
anychart.onDocumentReady(anychart.data.loadJsonFile("http://Server/Erase.svc/GetData",
function(data) {
// define a table with "Date" field as argument
// and date time format defined in the second parameter
var dataTable = anychart.data.table("Date", "dd/MM/yyyy");
// add data to the table
dataTable.addData([
{"Date":"01/01/2017","Cars":12,"Bikes":143,"Trucks":7},
{"Date":"01/02/2017","Cars":30,"Bikes":171,"Trucks":3},
{"Date":"01/03/2017","Cars":50,"Bikes":157,"Trucks":9},
{"Date":"01/04/2017","Cars":26,"Bikes":194,"Trucks":2},
{"Date":"01/05/2017","Cars":15,"Bikes":192,"Trucks":8}
]);
// define three mappings from the data
var mapping1 = data.mapAs({'value': "Cars"});
var mapping2 = data.mapAs({'value': "Bikes"});
var mapping3 = data.mapAs({'value': "Trucks"});
编辑:我修改了 javascript,但没有显示任何内容。console.log(data);
显示数据数组:
anychart.onDocumentReady(function(){
anychart.data.loadJsonFile("http://Server/Erase.svc/GetData", function(data) {
console.log(data);
var dataTable = anychart.data.table();
dataTable.addData(data);
var mapping1 = dataTable.mapAs({'value': "Cars"});
var mapping2 = dataTable.mapAs({'value': "Bikes"});
var mapping3 = dataTable.mapAs({'value': "Trucks"});
chart = anychart.stock();
var plot = chart.plot();
scale1 = anychart.scales.linear();
scale1.maximum(10);
plot.yAxis(1).enabled(true);
plot.yAxis(1).orientation("right");
plot.yAxis(1).scale("right");
line1 = plot.line(mapping1).name("Cars");
line2 = plot.line(mapping2).name("Bikes");
column = plot.column(mapping3).name("Trucks");
column.yScale(scale1);
plot.yAxis(1).stroke(column.color()).ticks().stroke(column.color());
chart.scroller().line(mapping1);
chart.title("Use mouse to draw zoom marquee");
chart.container("container").draw();
chart.startZoomMarquee(true, false);
chart.listen("dblclick", function(){
chart.selectRange("max");
});
})
});
任何帮助表示赞赏。