0
首先我是JS的初學者 我正在使用Amcharts來顯示一些傳感器值。 首先,我在Amcharts文檔中直接寫了它。JavaScript-Amscharts categoryAxis parseDate
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginRight": 40,
"marginLeft": 200,
"autoMarginOffset": 20,
"mouseWheelZoomEnabled":true,
"dataDateFormat": "YYYY-MM-DD-JJ:NN:SS",
"valueAxes": [{
"id": "v1",
"axisAlpha": 1,
"position": "left",
"ignoreAxisWidth":true,
"precision": 2,
"axisColor": PosColor1,
}],
"balloon": {
"borderThickness": 1,
"shadowAlpha": 0
},
"graphs": [{
"valueAxis": "v1",
"id": "Graph1",
"lineColor": PosColor1,
"negativeLineColor": NegColor1,
//"bullet": "round",
//"bulletBorderThickness": 1,
//"hideBulletsCount": 30,
"title": ChartValue1,
"valueField": ChartValue1,
//"fillAlphas": 0,
"balloonText": "<span style='font-size:22;'>[[Heizkurve]]</span>",
"balloonFunction": function(item, graph) {
var result = graph.balloonText;
for (var key in item.dataContext) {
if (item.dataContext.hasOwnProperty(key) && !isNaN(item.dataContext[key])) {
var formatted = AmCharts.formatNumber(item.dataContext[key], {
precision: chart.precision,
decimalSeparator: chart.decimalSeparator,
thousandsSeparator: chart.thousandsSeparator
}, 2);
result = result.replace("[[" + key + "]]", formatted);
}
}
return result;
}
}],
"chartScrollbar": {
"graph": "g1",
"oppositeAxis":false,
"offset":10,
"scrollbarHeight": 40,
"backgroundAlpha": 0,
"selectedBackgroundAlpha": 0.1,
"selectedBackgroundColor": "#888888",
"graphFillAlpha": 0,
"graphLineAlpha": 0.5,
"selectedGraphFillAlpha": 0,
"selectedGraphLineAlpha": 1,
"autoGridCount":true,
"color":"#AAAAAA"
},
"chartCursor": {
//"pan": true,
//"valueLineEnabled": true,
//"valueLineBalloonEnabled": true,
"categoryBalloonDateFormat": "MMM DD JJ:NN",
"cursorAlpha":1,
"cursorColor":"#258cbb",
"limitToGraph":"g1",
"valueLineAlpha":0.2,
//"valueZoomable":true
},
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"minPeriod": "fff",
"dashLength": 1,
"minorGridEnabled": true
},
"export": {
"enabled": true
},
"dataLoader": {
"url": file,
"format": "csv",
"showCurtain": true,
"showErrors": true,
"async": true,
"reload": 0,
//"timestamp": true,
"delimiter": ",",
"useColumnNames": true
},
........;
現在我試圖生成基於圖表對象,因爲我想用不同的數據動態更新它。 但是,當我添加「categoryAxis.oarseDate = true」,則不會顯示任何圖表。 如果我註釋它,繪製圖形,但X軸沒有像以前一樣格式化爲日期。
chart.dataProvider = chartData;
chart.categoryField = "date";
chart.addListener("dataUpdated", zoomChart);
var categoryAxis = chart.categoryAxis;
categoryAxis.minPeriod="fff";
categoryAxis.parseDates = true;
使用相同的.csv als數據源。 剛與Amcharts功能 「AmChartsLoadCSV」
function AmChartsLoadCSV(file,chart){
var newchart = new AmCharts.AmSerialChart();
newchart = chart;
AmCharts.loadFile(file, {}, function(data) {
var chartData = AmCharts.parseCSV(data, {
"delimiter": ",",
"useColumnNames": true,
"showCurtain": true,
"showErrors": true
});
var chart1 = MakeChart(chartData);
AddGraphtoChart(chart1,6);
return chart1;
});
我看到你正在使用的DataLoader,但您也設置數據提供程序。你的var chartData中有什麼? – Robbert
不,我只是使用dataProvider。 dataLoader僅在第一版本中使用,我直接定義了圖表「修復」(第一個代碼片段) CharData來自一個單獨的函數 - >我在第一篇文章中添加了它 – Vertigo1206