Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][PHP] Problem z prasowaniem daty dla amCharts
krzysiekkurowski
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 13.02.2005

Ostrzeżenie: (10%)
X----


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ą:
  1. year:<?php print ($row['dattim']); ?>,
jak mogę użyć new Date() aby skrypt zaczął działać ?

Proszę o pomoc.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>amCharts examples</title>
  6. <link rel="stylesheet" href="style.css" type="text/css">
  7. <script src="amcharts/amcharts.js" type="text/javascript"></script>
  8. <script type="text/javascript">
  9. var chart;
  10. var graph;
  11.  
  12.  
  13. // months in JS are zero-based, 0 means January
  14. var chartData = [
  15. <?php foreach($last24hourValues as $row) { ?>
  16. {
  17. year:<?php print ($row['dattim']); ?>,
  18. value: <?php print number_format($row['Aussen'], 2); ?>
  19. }
  20. <?php } ?>
  21.  
  22. ];
  23.  
  24.  
  25. AmCharts.ready(function () {
  26. // SERIAL CHART
  27. chart = new AmCharts.AmSerialChart();
  28. chart.pathToImages = "amcharts/images/";
  29. chart.dataProvider = chartData;
  30. chart.marginLeft = 10;
  31. chart.categoryField = "year";
  32. chart.zoomOutButton = {
  33. backgroundColor: '#000000',
  34. backgroundAlpha: 0.15
  35. };
  36.  
  37. // listen for "dataUpdated" event (fired when chart is inited) and call zoomChart method when it happens
  38. chart.addListener("dataUpdated", zoomChart);
  39.  
  40. // AXES
  41. // category
  42. var categoryAxis = chart.categoryAxis;
  43. categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
  44. categoryAxis.minPeriod = "YYYY"; // our data is yearly, so we set minPeriod to YYYY
  45. categoryAxis.gridAlpha = 0;
  46.  
  47. // value
  48. var valueAxis = new AmCharts.ValueAxis();
  49. valueAxis.axisAlpha = 0;
  50. valueAxis.inside = true;
  51. chart.addValueAxis(valueAxis);
  52.  
  53. // GRAPH
  54. graph = new AmCharts.AmGraph();
  55. graph.type = "smoothedLine"; // this line makes the graph smoothed line.
  56. graph.lineColor = "#d1655d";
  57. graph.negativeLineColor = "#637bb6"; // this line makes the graph to change color when it drops below 0
  58. graph.bullet = "round";
  59. graph.bulletSize = 5;
  60. graph.lineThickness = 2;
  61. graph.valueField = "value";
  62. chart.addGraph(graph);
  63.  
  64. // CURSOR
  65. var chartCursor = new AmCharts.ChartCursor();
  66. chartCursor.cursorAlpha = 0;
  67. chartCursor.cursorPosition = "mouse";
  68. chartCursor.categoryBalloonDateFormat = "YYYY";
  69. chart.addChartCursor(chartCursor);
  70.  
  71. // SCROLLBAR
  72. var chartScrollbar = new AmCharts.ChartScrollbar();
  73. chartScrollbar.graph = graph;
  74. chartScrollbar.backgroundColor = "#DDDDDD";
  75. chartScrollbar.scrollbarHeight = 30;
  76. chartScrollbar.selectedBackgroundColor = "#FFFFFF";
  77. chart.addChartScrollbar(chartScrollbar);
  78.  
  79. // WRITE
  80. chart.write("chartdiv");
  81. });
  82.  
  83. // this method is called when chart is first inited as we listen for "dataUpdated" event
  84. function zoomChart() {
  85. // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
  86. chart.zoomToDates(new Date(2000, 0), new Date(2003, 0));
  87. }
  88. </script>
  89. </head>
  90.  
  91. <body>
  92. <div id="chartdiv" style="width:100%; height:400px;"></div>
  93. </body>
  94.  
  95. </html>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 22:23