好!!!抱歉我的英语倒了。 这是我与amcharts的问题。我在新的proyect中做了一些图形。 该项目建立在MVC和PHP5之上。 我们这样做是为了获得结果:
// var chartData = AmCharts.loadJSON(baseurl +'libs / jsonvalueconsumption.php?id = ...);
使用amcharts.loadjson函数可以在amcharts的例子中给出。
但是现在我们正在通过AJAX做。问题???? 我们得到了相同的结果,代码的所有步骤都相同,但是控制台引发了一个问题:
无法读取未定义ammod.js.pagespeed.ce.sQT2FSFmcG.js的属性'construct':49
这是我们的js必须在div上获取图形:
//AmCharts.ready(function() {
var firstData = $.ajax({
type: 'POST',
url: baseurl+'action/charts/SOME_FUNCTION',
data: { id : id },
dataType: 'JSON',
async: false,
success: function(getdata) {
return getdata;
}
}).responseText;
chart = new AmCharts.AmStockChart();
chart.pathToImages = "http://www.amcharts.com/lib/images/";
chart.dataDateFormat = "YYYY-MM-DD h:i:s";
var obj = JSON.parse(firstData);
for(i=0;i<obj.length;i++) {
var id_something = obj[i]['id'];
var secondData = $.ajax({
type: 'POST',
url: baseurl+'action/charts/ANOTHER_SOME_FUNCTION',
data: { id_something : id_something, value1 : value1, value2 : value2 },
dataType: 'JSON',
async: false,
success: function(getdata) {
return getdata;
}
}).responseText;
var chartData = JSON.parse(secondData);
var dataSet = new AmCharts.DataSet();
dataSet.title = obj[i]['name'];
dataSet.fieldMappings = [{
fromField: "value",
toField: "value"
}, {
fromField: "volume",
toField: "volume"
}];
dataSet.dataProvider = chartData;
dataSet.categoryField = "date";
chart.dataSets.push(dataSet);
}
// first stock panel
var stockPanel1 = new AmCharts.StockPanel();
stockPanel1.showCategoryAxis = false;
stockPanel1.title = "Valor";
stockPanel1.percentHeight = 70;
// graph of first stock panel
var graph1 = new AmCharts.StockGraph();
graph1.valueField = "value";
graph1.comparable = true;
graph1.compareField = "value";
graph1.compareGraphBalloonText="[[value]] kwh"; //mostrar las unidades de medida en el balloon de las comparaciones
graph1.balloonText= "[[value]] kwh"; //mostrar las unidades de medida en el balloon
stockPanel1.addStockGraph(graph1);
// create stock legend
stockPanel1.stockLegend = new AmCharts.StockLegend();
stockPanel1.stockLegend.valueTextRegular="[[value]] kwh"; ////mostrar las unidades de medida en el legend
// second stock panel
var stockPanel2 = new AmCharts.StockPanel();
stockPanel2.title = "Volumen";
stockPanel2.percentHeight = 30;
var graph2 = new AmCharts.StockGraph();
graph2.valueField = "volume";
graph2.type = "column";
graph2.showBalloon = false;
graph2.fillAlphas = 1;
stockPanel2.addStockGraph(graph2);
stockPanel2.stockLegend = new AmCharts.StockLegend();
stockPanel2.stockLegend.valueTextRegular="[[value]] kwh"; ////mostrar las unidades de medida en el legend
// set panels to the chart
chart.panels = [stockPanel1, stockPanel2];
// OTHER SETTINGS ////////////////////////////////////
var scrollbarSettings = new AmCharts.ChartScrollbarSettings();
scrollbarSettings.graph = graph1;
scrollbarSettings.updateOnReleaseOnly = true;
scrollbarSettings.usePeriod = "10mm";
chart.chartScrollbarSettings = scrollbarSettings;
var cursorSettings = new AmCharts.ChartCursorSettings();
cursorSettings.valueBalloonsEnabled = true;
chart.chartCursorSettings = cursorSettings;
// PERIOD SELECTOR ///////////////////////////////////
var periodSelector = new AmCharts.PeriodSelector();
periodSelector.periods = [{
period: "hh",
count: 24,
label: "ddd"
}, {
period: "hh",
count: 48,
label: "dd"
}, {
period: "hh",
count: 120,
label: "ddd"
}, {
period: "hh",
count: 240,
label: "dia"
}, {
period: "MAX",
label: "MAX"
}];
chart.periodSelector = periodSelector;
var panelsSettings = new AmCharts.PanelsSettings();
panelsSettings.usePrefixes = true;
chart.panelsSettings = panelsSettings;
// DATA SET SELECTOR
var dataSetSelector = new AmCharts.DataSetSelector();
dataSetSelector.position = "left";
chart.dataSetSelector = dataSetSelector;
chart.write('chartdiv');
});
如果有人想要更多信息或解决方案会很棒!!!!感谢
答案 0 :(得分:7)
我确实遇到了同样的错误,解决方案非常简单:
在amCharts文件夹中,您将找到三个.js文件:“amcharts.js”,“amstock.js”和“serial.js”。
你必须确保将它们包含在你的HTML代码中在这个严格的序列中(这里的顺序很重要): amcharts.js,serial.js,amstock.js
这就是全部; - )
答案 1 :(得分:1)
AmCharts.loadJSON不是构建方法,您应该自己添加它,就像本教程中描述的那样:http://blog.amcharts.com/2013/09/tutorial-using-php-to-hook-up-charts-to.html