Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][MySQL][PHP]Google charts dane z mysql
mateoosh_tar
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.07.2011

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


Witam. Posiadam tabelę w mysql z danymi rozmiar i pwaga(waga procentowa).

Chciałem wstawić dane z php do skryptu html. Zrobiłem coś takiego, lecz nie działa:

  1.  
  2. <html>
  3.  
  4. <?php
  5. $db = mysql_connect('localhost', 'root', 'admin');
  6. mysql_select_db('nr_id', 'raporty','magazyn', $custombaza);
  7. //polskie kodowanie
  8. mysql_query("SET NAMES utf8");
  9. mysql_query("SET CHARACTER SET utf8");
  10. mysql_query("SET collation_connection = utf8_polish_ci");
  11.  
  12.  
  13. function zrobzmienne()
  14. {
  15. $wysz_part = mysql_query("select rozmiar,pwaga FROM raporty.37_9_6_10_1") or die('Błąd zapytania: '.mysql_error());
  16. while ($wysz = mysql_fetch_assoc($wysz_part))
  17. {
  18. $asd[''] ='[\''.$wysz['rozmiar'].'\', '.$wysz['pwaga'].'],<br/>';
  19.  
  20.  
  21. }
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. ?>
  29. <head>
  30. <!--Load the AJAX API-->
  31. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  32. <script type="text/javascript">
  33.  
  34. // Load the Visualization API and the piechart package.
  35. google.load('visualization', '1.0', {'packages':['corechart']});
  36.  
  37. // Set a callback to run when the Google Visualization API is loaded.
  38. google.setOnLoadCallback(drawChart);
  39.  
  40. // Callback that creates and populates a data table,
  41. // instantiates the pie chart, passes in the data and
  42. // draws it.
  43. function drawChart() {
  44.  
  45. // Create the data table.
  46. var data = new google.visualization.DataTable();
  47. data.addColumn('string', 'Topping');
  48. data.addColumn('number', 'Slices');
  49. data.addRows([
  50. <?php
  51. zrobzmienne();
  52. ?>
  53. ]);
  54.  
  55. // Set chart options
  56. var options = {'title':'Procentowy wykres raportu',
  57. 'width':400,
  58. 'height':300};
  59.  
  60. // Instantiate and draw our chart, passing in some options.
  61. var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  62. chart.draw(data, options);
  63. }
  64. </script>
  65. </head>
  66.  
  67. <body>
  68. <!--Div that will hold the pie chart-->
  69. <div id="chart_div"></div>
  70. </body>
  71. </html>
  72.  


Tutaj podaję linka do przykładu jak powinny być zapisane dane w skrypcie:
http://code.google.com/intl/pl/apis/chart/...uick_start.html

Proszę o podpowiedzi jak powinienem postąpić.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mateoosh_tar
post
Post #2





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 28.07.2011

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


Tfuuu...

nie skryptu html, a sktyptu js...

W podanym przykładzie podałem miejsce gdzie mają być wstawione dane w skrypcie js, mianowicie:


  1. <?php
  2. zrobzmienne();
  3. ?>



Dane muszą być zapisane w formacie:

['info1', wartość1],
['info2', wartosc2],
itd itd

czyli np:

['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]


czyli w moim przypadku:

['Rozmiar 0-60', 0.30],
['Rozmiar 60-65', 2.06],
['Rozmiar 65-70', 9.21],
['Rozmiar 70-75', 23.92],
['Rozmiar 75-80', 31.64],
['Rozmiar 80-85', 20.96],
['Rozmiar 85-90', 9.09],
['Rozmiar 90-95', 2.42],
['Rozmiar 95+', 0.32],


stąd funkcja:

  1.  
  2. function zrobzmienne()
  3. {
  4. $wysz_part = mysql_query("select rozmiar,pwaga FROM raporty.37_9_6_10_1") or die('Błąd zapytania: '.mysql_error());
  5. while ($wysz = mysql_fetch_assoc($wysz_part))
  6. {
  7. $asd[''] ='[\''.$wysz['rozmiar'].'\', '.$wysz['pwaga'].'],<br/>';
  8. }
  9. }


gdy przerobię ją na np:
  1. function zrobzmienne()
  2. {
  3. $wysz_part = mysql_query("select rozmiar,pwaga FROM raporty.37_9_6_10_1") or die('Błąd zapytania: '.mysql_error());
  4. while ($wysz = mysql_fetch_assoc($wysz_part))
  5. {
  6. $asd[''] ='[\''.$wysz['rozmiar'].'\', '.$wysz['pwaga'].'],<br/>';
  7. echo $asd[''];
  8.  
  9. }
  10.  
  11. }



otrzymuję prawidłowe wartości w echo. Mam po prostu problem jak wywołać je w zamiast

['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]

w:

  1. <html>
  2. <head>
  3. <!--Load the AJAX API-->
  4. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  5. <script type="text/javascript">
  6.  
  7. // Load the Visualization API and the piechart package.
  8. google.load('visualization', '1.0', {'packages':['corechart']});
  9.  
  10. // Set a callback to run when the Google Visualization API is loaded.
  11. google.setOnLoadCallback(drawChart);
  12.  
  13. // Callback that creates and populates a data table,
  14. // instantiates the pie chart, passes in the data and
  15. // draws it.
  16. function drawChart() {
  17.  
  18. // Create the data table.
  19. var data = new google.visualization.DataTable();
  20. data.addColumn('string', 'Topping');
  21. data.addColumn('number', 'Slices');
  22. data.addRows([
  23. ['Mushrooms', 3],
  24. ['Onions', 1],
  25. ['Olives', 1],
  26. ['Zucchini', 1],
  27. ['Pepperoni', 2]
  28. ]);
  29.  
  30. // Set chart options
  31. var options = {'title':'How Much Pizza I Ate Last Night',
  32. 'width':400,
  33. 'height':300};
  34.  
  35. // Instantiate and draw our chart, passing in some options.
  36. var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  37. chart.draw(data, options);
  38. }
  39. </script>
  40. </head>
  41.  
  42. <body>
  43. <!--Div that will hold the pie chart-->
  44. <div id="chart_div"></div>
  45. </body>
  46. </html>


Może teraz troszkę rozjaśniłem ;]
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 - 20:47