Guest User

Untitled

a guest
Sep 20th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  4. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  5. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  6. <script type="text/javascript">
  7. google.charts.load('current', {'packages':['sankey']});
  8. google.charts.setOnLoadCallback(drawChart);
  9.  
  10.  
  11. function drawChart() {
  12. var json;
  13. $.ajax({
  14. //var req = $get.JSON({
  15. type: 'POST',
  16. url: 'http://localhost:9200/<my_index_name>/<type>/<id>/_source?pretty=true',
  17.  
  18. data : JSON.stringify(
  19. {
  20. "query" : { "match_all" : {} }
  21. }),
  22. dataType : "jsonp",
  23. //cache: true,
  24. //async: false,
  25. success: function(data){
  26. json = data;
  27. console.log(JSON.parse(data));
  28. var jdata = {};
  29. jdata.cols = [
  30. {
  31. "id": "",
  32. "label": "col1",
  33. "type": "string"
  34. },
  35. {
  36. "id": "",
  37. "label": "col2",
  38. "type": "number"
  39. }
  40. ];
  41. //document.write("hello");
  42.  
  43. //document.write(data);
  44. //need loop:
  45. jdata.rows = [
  46. {
  47. "c": [
  48. {
  49. "v": json.hits.hits[0]._source.col1
  50. },
  51. {
  52. "v": json.hits.hits[0]._source.col2
  53. }
  54. ]
  55. }
  56. ];
  57. var data = new google.visualization.DataTable(jdata);
  58.  
  59. var chart = new google.visualization.PieChart(document.getElementById('piechart_div'));
  60. chart.draw(data, {is3D: true, title: 'Multi Routes per Lane', width: 600, height: 440});
  61. }
  62. });
  63.  
  64.  
  65. }
  66. </script>
  67. </head>
  68. <body>
  69. <div id="piechart_div"> </div>
  70. </body>
  71. </html>
Add Comment
Please, Sign In to add comment