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
 
Start new topic
Odpowiedzi
brzanek
post
Post #2





Grupa: Zarejestrowani
Postów: 429
Pomógł: 0
Dołączył: 8.11.2012

Ostrzeżenie: (0%)
-----


Witam sory za odkopanie ale mam podobny problem.
Tak u mnie wygląda plik odpowiedzialny za pobieranie danych z bazy danych mysql
dane.php
  1. <?php
  2. ini_set( 'display_errors', 'On' );
  3. error_reporting( E_ALL );
  4.  
  5. $con=@mysql_connect('localhost','login','haslo');
  6. mysql_select_db("nazwa_bazy_danych", $con);
  7. mysql_query("SET CHARSET utf8");
  8. $result = mysql_query("SELECT htime, htemperature FROM prognoza_godzinowa WHERE hid_miasto =1") or die(mysql_error());
  9. while($row = mysql_fetch_array($result)) {
  10. $rows[] = array(
  11. "htime" => date("d.m.Y H:i", $row['htime']),
  12. "htemperature" => $row[ 'htemperature' ]
  13. );
  14. }
  15. echo json_encode( $rows );


A tak wygląda plik wyświetlający wykres
  1. <!-- Styles -->
  2. <style>
  3. #chartdiv {
  4. width : 100%;
  5. height : 500px;
  6. }
  7.  
  8. </style>
  9.  
  10. <!-- Resources -->
  11. <script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
  12. <script src="https://www.amcharts.com/lib/3/serial.js"></script>
  13. <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
  14. <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
  15. <script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
  16. <!-- Chart code -->
  17. <script>
  18. var chartData = ('http://brzanek.webd.pl/charts2/dane.php');
  19. var chart = AmCharts.makeChart("chartdiv", {
  20. "type": "serial",
  21. "theme": "light",
  22. "marginRight": 40,
  23. "marginLeft": 40,
  24. "autoMarginOffset": 20,
  25. "mouseWheelZoomEnabled":true,
  26. "dataDateFormat": "YYYY-MM-DD JJ:NN",
  27. "valueAxes": [{
  28. "id": "v1",
  29. "axisAlpha": 0,
  30. "position": "left",
  31. "ignoreAxisWidth":true
  32. }],
  33. "balloon": {
  34. "borderThickness": 1,
  35. "shadowAlpha": 0
  36. },
  37. "graphs": [{
  38. "id": "g1",
  39. "balloon":{
  40. "drop":true,
  41. "adjustBorderColor":false,
  42. "color":"#ffffff"
  43. },
  44. "bullet": "round",
  45. "bulletBorderAlpha": 1,
  46. "bulletColor": "#FFFFFF",
  47. "bulletSize": 5,
  48. "hideBulletsCount": 50,
  49. "lineThickness": 2,
  50. "title": "red line",
  51. "useLineColorForBulletBorder": true,
  52. "valueField": "htemperature",
  53. "balloonText": "<span style='font-size:18px;'>[[htemperature]]</span>"
  54. }],
  55. "chartScrollbar": {
  56. "graph": "g1",
  57. "oppositeAxis":false,
  58. "offset":30,
  59. "scrollbarHeight": 80,
  60. "backgroundAlpha": 0,
  61. "selectedBackgroundAlpha": 0.1,
  62. "selectedBackgroundColor": "#888888",
  63. "graphFillAlpha": 0,
  64. "graphLineAlpha": 0.5,
  65. "selectedGraphFillAlpha": 0,
  66. "selectedGraphLineAlpha": 1,
  67. "autoGridCount":true,
  68. "color":"#AAAAAA"
  69. },
  70. "chartCursor": {
  71. "pan": true,
  72. "valueLineEnabled": true,
  73. "valueLineBalloonEnabled": true,
  74. "cursorAlpha":1,
  75. "cursorColor":"#258cbb",
  76. "limitToGraph":"g1",
  77. "valueLineAlpha":0.2,
  78. "valueZoomable":true
  79. },
  80. "valueScrollbar":{
  81. "oppositeAxis":false,
  82. "offset":50,
  83. "scrollbarHeight":10
  84. },
  85. "categoryField": "htime",
  86. "categoryAxis": {
  87. "parseDates": true,
  88. "dashLength": 1,
  89. "minorGridEnabled": true
  90. },
  91. "export": {
  92. "enabled": true
  93. },
  94. "dataProvider": chartData,
  95.  
  96.  
  97. });
  98.  
  99. chart.addListener("rendered", zoomChart);
  100.  
  101. zoomChart();
  102.  
  103. function zoomChart() {
  104. chart.zoomToIndexes(chart.dataProvider.length - 10, chart.dataProvider.length - 1);
  105. }
  106. </script>
  107.  
  108. <!-- HTML -->
  109. <div id="chartdiv"></div>

Problem w tym, że nic nie pojawia się na wykresie. Kto podpowie dlaczego tak się dzieje.
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 26.09.2025 - 05:10