Witam, chciałbym zczytać dane z bazy mysql i wyswietlić je używając skryptu amCharts.
Niestety problem w tym ze nie mogę poradzić sobie z prasowaniem daty z mysql i po wczytaniu strony nic się nie pojawia.
Problem dokładnie jest z linijką:
year:<?php print ($row['dattim']); ?>,
jak mogę użyć new Date() aby skrypt zaczął działać ?
Proszę o pomoc.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="style.css" type="text/css"> <script src="amcharts/amcharts.js" type="text/javascript"></script> <script type="text/javascript"> var chart;
var graph;
// months in JS are zero-based, 0 means January
var chartData = [
<?php foreach($last24hourValues as $row) { ?>
{
year:<?php print ($row['dattim']); ?>,
value: <?php print number_format($row['Aussen'], 2); ?>
}
<?php } ?>
];
AmCharts.ready(function () {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "amcharts/images/";
chart.dataProvider = chartData;
chart.marginLeft = 10;
chart.categoryField = "year";
chart.zoomOutButton = {
backgroundColor: '#000000',
backgroundAlpha: 0.15
};
// listen for "dataUpdated" event (fired when chart is inited) and call zoomChart method when it happens
chart.addListener("dataUpdated", zoomChart);
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "YYYY"; // our data is yearly, so we set minPeriod to YYYY
categoryAxis.gridAlpha = 0;
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0;
valueAxis.inside = true;
chart.addValueAxis(valueAxis);
// GRAPH
graph = new AmCharts.AmGraph();
graph.type = "smoothedLine"; // this line makes the graph smoothed line.
graph.lineColor = "#d1655d";
graph.negativeLineColor = "#637bb6"; // this line makes the graph to change color when it drops below 0
graph.bullet = "round";
graph.bulletSize = 5;
graph.lineThickness = 2;
graph.valueField = "value";
chart.addGraph(graph);
// CURSOR
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorAlpha = 0;
chartCursor.cursorPosition = "mouse";
chartCursor.categoryBalloonDateFormat = "YYYY";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chartScrollbar.graph = graph;
chartScrollbar.backgroundColor = "#DDDDDD";
chartScrollbar.scrollbarHeight = 30;
chartScrollbar.selectedBackgroundColor = "#FFFFFF";
chart.addChartScrollbar(chartScrollbar);
// WRITE
chart.write("chartdiv");
});
// this method is called when chart is first inited as we listen for "dataUpdated" event
function zoomChart() {
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
chart.zoomToDates(new Date(2000, 0), new Date(2003, 0));
}
<div id="chartdiv" style="width:100%; height:400px;"></div>