example11_datasource.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <html>
  2. <head>
  3. <title>Timeline demo</title>
  4. <style>
  5. body {font: 10pt arial;}
  6. </style>
  7. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  8. <script type="text/javascript" src="../timeline.js"></script>
  9. <link rel="stylesheet" type="text/css" href="../timeline.css">
  10. <script type="text/javascript">
  11. google.load("visualization", "1");
  12. var urlSpreadsheet = "https://spreadsheets.google.com/a/almende.org/ccc?key=tpN13qnPm37g3qTXT5Hc9sg&hl=en#gid=0";
  13. var urlData = "data.php";
  14. var initialized = false;
  15. var query;
  16. var vis;
  17. // Set callback to run when API is loaded
  18. google.setOnLoadCallback(initialize);
  19. function initialize() {
  20. initialized = true;
  21. }
  22. function load(url) {
  23. if (!initialized) {
  24. alert("One moment please... still busy loading Google Visualization API");
  25. return;
  26. }
  27. if (url == undefined) {
  28. dataSourceUrl = document.getElementById("dataSourceUrl").value
  29. } else {
  30. dataSourceUrl = url;
  31. }
  32. // if the entered url is a google spreadsheet url, replace the part
  33. // "/ccc?" with "/tq?" in order to retrieve a neat data query result
  34. if (dataSourceUrl.indexOf("/ccc?")) {
  35. dataSourceUrl.replace("/ccc?", "/tq?");
  36. }
  37. handleQueryResponse = function(response) {
  38. if (response.isError()) {
  39. alert('Error in query: ' + response.getMessage() + ', ' + response.getDetailedMessage());
  40. return;
  41. }
  42. // retrieve the data from the query response
  43. var data = response.getDataTable();
  44. // specify options
  45. options = {
  46. width: "100%",
  47. height: "300px",
  48. editable: true,
  49. layout: "box"
  50. };
  51. // Instantiate our timeline object.
  52. vis = new links.Timeline(document.getElementById('mytimeline'));
  53. // Draw our timeline with the created data and options
  54. vis.draw(data, options);
  55. }
  56. query && query.abort();
  57. query = new google.visualization.Query(dataSourceUrl);
  58. query.send(handleQueryResponse);
  59. }
  60. function loadDataHtml() {
  61. document.getElementById("dataSourceUrl").value = urlData;
  62. load(urlData);
  63. }
  64. function loadSpreadSheet() {
  65. document.getElementById("dataSourceUrl").value = urlSpreadsheet;
  66. load(urlSpreadsheet);
  67. }
  68. </script>
  69. </head>
  70. <body>
  71. <p>Enter a datasource and click the button "Go".</p>
  72. <p>
  73. Datasource: <input type="text" id="dataSourceUrl" value="data.php" style="width: 600px;">
  74. <input type="button" value="Go" onclick="load();">
  75. </p>
  76. <p>
  77. Examples:
  78. </p>
  79. <p>
  80. <a href="javascript:loadDataHtml();">Open data.php</a> (Works only if you run the example on a PHP server)<br>
  81. <a href="javascript:loadSpreadSheet();">Open a Google spreadsheet</a>
  82. (or <a href="" onclick="javascript:window.open(urlSpreadsheet); return false;">view</a> this sheet)<br>
  83. </p>
  84. <div id="mytimeline"></div>
  85. </body>
  86. </html>