Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Wykres z danymi z bazy MySQL
brzanek
post 18.09.2016, 08:43:49
Post #1





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

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


Witam mam problem z pokazaniem danych pobieranych z kilku tabel na wykresie highcharts.
Moje tabele nazywają się
prognoza_choszczno
prognoza_szczecin
prognoza_koszalin

W każdej tabeli mam pola
id, dzien, dzientempmax, dzientempmax, dzien1, dzien1tempmax, dzien1tempmax, dzien2, dzien2tempmax, dzien2tempmax itd
Chciałbym te dane ze wszystkich tabel wyświetlić na jednym wykresie.
Coś takiego
wykres

Ten post edytował brzanek 18.09.2016, 09:19:10
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
Kshyhoo
post 18.09.2016, 08:51:01
Post #2





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Cytat(brzanek @ 18.09.2016, 09:43:49 ) *
Witam mam problem z pokazaniem danych pobieranych z kilku tabel na wykresie highcharts.

Jaki masz problem z pokazaniem danych?


--------------------
Go to the top of the page
+Quote Post
brzanek
post 18.09.2016, 08:58:01
Post #3





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

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


Problem jest taki, że nie wiem jak to pobrać i wyświetlić na wykresie.
Go to the top of the page
+Quote Post
Kshyhoo
post 18.09.2016, 09:02:19
Post #4





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




No pobrać z bazy, to chyba, to chyba umiesz? A potem do tablicy:
  1. series: [{
  2. name: 'Tokyo',
  3. data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  4. }, {


--------------------
Go to the top of the page
+Quote Post
brzanek
post 18.09.2016, 09:42:38
Post #5





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

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


Problem w tym, że moje pola w tabeli wyglądają tak:
id, dzien, dzientempmax, dzientempmax, dzientempodcz, dzienwiatr, dziencisnienie, dzien1, dzien1tempmax, dzien1tempmin, dzien1tempodcz, dzien1wiatr, dzien1cisnienie, dzien2, dzien2tempmax, dzien2tempmin, dzien2tempodcz, dzien2wiatr, dzien2cisnienie, itd
Ja potrzebuję wyciągnąć tylko takie dane
dzien, dzientempmax, dzientempmax, dzien1, dzien1tempmax, dzien1tempmax, dzien2, dzien2tempmax, dzien2tempmax itd
Kolejne id dodawane jest automatycznie co 2 godziny.
Teraz te dane będę chciał wyświetlić na wykresie jaki pokazałem wcześniej.
Zaznaczam, że dane pochodzą z jednego id.

Pobrałem dane z tabeli te które mnie interesowały tylko teraz jak je wyświetlić na wykresie.
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con) {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6. mysql_select_db("brzanek_prognoza", $con);
  7.  
  8. $result = mysql_query("SELECT id, dzien, dzientempmax, dzientempmin , dzien1 , dzien1tempmax , dzien1tempmin , dzien2 , dzien2tempmax , dzien2tempmin , dzien3 , dzien3tempmax , dzien3tempmin FROM prognoza_choszczno ORDER BY id DESC LIMIT 1");
  9. while($row = mysql_fetch_array($result)) {
  10. echo $row['dzien'] . "\t" . $row['dzientempmax']. "\t" . $row['dzientempmin']. "\n";
  11. echo $row['dzien1'] . "\t" . $row['dzien1tempmax']. "\t" . $row['dzien1tempmin']. "\n";
  12. echo $row['dzien2'] . "\t" . $row['dzien2tempmax']. "\t" . $row['dzien2tempmin']. "\n";
  13. echo $row['dzien3'] . "\t" . $row['dzien3tempmax']. "\t" . $row['dzien3tempmin']. "\n";
  14. }
  15. ?>


Ten post edytował brzanek 18.09.2016, 09:31:06
Go to the top of the page
+Quote Post
Kshyhoo
post 18.09.2016, 09:51:04
Post #6





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Np: tak, lub tablica z php do javascript


--------------------
Go to the top of the page
+Quote Post
brzanek
post 18.09.2016, 10:22:43
Post #7





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

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


Cytat(Kshyhoo @ 18.09.2016, 10:51:04 ) *

Niewiele mi to mówi.
Tak wygląda plik z wykresem ze strony highcharts
http://jsfiddle.net/gh/get/jquery/1.9.1/hi...emo/line-basic/
  1. $(function () {
  2. $('#container').highcharts({
  3. title: {
  4. text: 'Monthly Average Temperature',
  5. x: -20 //center
  6. },
  7. subtitle: {
  8. text: 'Source: WorldClimate.com',
  9. x: -20
  10. },
  11. xAxis: {
  12. categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  13. 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  14. },
  15. yAxis: {
  16. title: {
  17. text: 'Temperature (°C)'
  18. },
  19. plotLines: [{
  20. value: 0,
  21. width: 1,
  22. color: '#808080'
  23. }]
  24. },
  25. tooltip: {
  26. valueSuffix: '°C'
  27. },
  28. legend: {
  29. layout: 'vertical',
  30. align: 'right',
  31. verticalAlign: 'middle',
  32. borderWidth: 0
  33. },
  34. series: [{
  35. name: 'Tokyo',
  36. data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  37. }, {
  38. name: 'New York',
  39. data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
  40. }, {
  41. name: 'Berlin',
  42. data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
  43. }, {
  44. name: 'London',
  45. data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
  46. }]
  47. });
  48. });
Go to the top of the page
+Quote Post
Kshyhoo
post 18.09.2016, 10:31:35
Post #8





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Dane do wykresu musisz podać w takiej formie:
  1. series: [{
  2. name: 'Tokyo',
  3. data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  4. }, {

Dlatego podałem Ci link. Musisz przekazać w postaci tablicy. data to dane do wykresu.


--------------------
Go to the top of the page
+Quote Post
brzanek
post 18.09.2016, 10:56:54
Post #9





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

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


Nie wiem czy dobrze ale zrobiłem tak
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con) {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6. mysql_select_db("brzanek_prognoza", $con);
  7. $result = mysql_query("SELECT id, dzien, dzientempmax, dzientempmin, dzien1 , dzien1tempmax , dzien1tempmin , dzien2 , dzien2tempmax , dzien2tempmin , dzien3 , dzien3tempmax , dzien3tempmin, dzien4, dzien4tempmax, dzien4tempmin, dzien5, dzien5tempmax, dzien5tempmin, dzien6, dzien6tempmax, dzien6tempmin, dzien7, dzien7tempmax, dzien7tempmin, dzien8, dzien8tempmax, dzien8tempmin, dzien9, dzien9tempmax, dzien9tempmin FROM prognoza_choszczno ORDER BY id DESC LIMIT 1");
  8. while($row = mysql_fetch_array($result)) {
  9. $max[] = array(
  10. 'dzientempmax' => $row['dzientempmax'],
  11. 'dzien1tempmax' => $row['dzien1tempmax'],
  12. 'dzien2tempmax' => $row['dzien2tempmax'],
  13. 'dzien3tempmax' => $row['dzien3tempmax'],
  14. 'dzien4tempmax' => $row['dzien4tempmax'],
  15. 'dzien5tempmax' => $row['dzien5tempmax'],
  16. 'dzien6tempmax' => $row['dzien6tempmax'],
  17. 'dzien7tempmax' => $row['dzien7tempmax'],
  18. 'dzien8tempmax' => $row['dzien8tempmax'],
  19. 'dzien9tempmax' => $row['dzien9tempmax']
  20. );
  21. echo json_encode($max);
  22. }
  23. ?>

O to chodziło?

Ten post edytował brzanek 18.09.2016, 10:57:17
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 08:10