Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. enter code here<script type="text/javascript">
  2. var endpoint = "http://sws.ifi.uio.no/sparql/world";
  3. var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX owl: <http://www.w3.org/2002/07/owl#>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX w: <http://sws.ifi.uio.no/ont/world.owl#>PREFIX dbpo: <http://dbpedia.org/ontology/>PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>PREFIX dct: <http://purl.org/dc/terms/>PREFIX fn: <http://www.w3.org/2005/xpath-functions#>PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>PREFIX npdv: <http://sws.ifi.uio.no/vocab/npd#>PREFIX npdv2: <http://sws.ifi.uio.no/vocab/npd-v2#>PREFIX geos: <http://www.opengis.net/ont/geosparql#>SELECT * WHERE{ [] a w:Country ; w:hasName ?Name ; w:hasCountryPopulation ?Population ; } ORDER BY DESC(?Population) LIMIT 10" ;
  4.  
  5. var endpoint = "http://sws.ifi.uio.no/sparql/world";
  6. var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX owl: <http://www.w3.org/2002/07/owl#>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX w: <http://sws.ifi.uio.no/ont/world.owl#>PREFIX dbpo: <http://dbpedia.org/ontology/>PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>PREFIX dct: <http://purl.org/dc/terms/>PREFIX fn: <http://www.w3.org/2005/xpath-functions#>PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>PREFIX npdv: <http://sws.ifi.uio.no/vocab/npd#>PREFIX npdv2: <http://sws.ifi.uio.no/vocab/npd-v2#>PREFIX geos: <http://www.opengis.net/ont/geosparql#>SELECT * WHERE{ [] a w:City ; w:hasName ?Name ; w:hasCityPopulation ?Population ; } ORDER BY DESC(?Population) LIMIT 10";
  7.  
  8. var resultArray = ['test'];
  9. // Define a callback function to receive the SPARQL JSON result.
  10. function myCallback(str) {
  11. // Convert result to JSON
  12. var jsonObj = eval('(' + str + ')');
  13.  
  14. // Build up an array of results.
  15. resultArray = new Array();
  16. resultArray[0] = jsonObj.head.vars;
  17. for(var i = 0; i < jsonObj.results.bindings.length; i++) {
  18. resultArray[i+1] = new Array();
  19. resultArray[i+1][0] = jsonObj.results.bindings[i].Name.value;
  20. resultArray[i+1][1] = jsonObj.results.bindings[i].Population.value / 1000;
  21. }
  22. }
  23.  
  24. // Make the query.
  25. sparqlQueryJson(query, endpoint, myCallback, false);
  26.  
  27. google.load("visualization", "1", {packages:["corechart"]});
  28.  
  29. function drawChart() {
  30.  
  31. var item = document.getElementById('selQuery').value;
  32.  
  33. var item2 = document.getElementById('graphs').value;
  34.  
  35. if (item == 'query1')
  36. {
  37. var endpoint = "http://sws.ifi.uio.no/sparql/world";
  38. var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX owl: <http://www.w3.org/2002/07/owl#>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX w: <http://sws.ifi.uio.no/ont/world.owl#>PREFIX dbpo: <http://dbpedia.org/ontology/>PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>PREFIX dct: <http://purl.org/dc/terms/>PREFIX fn: <http://www.w3.org/2005/xpath-functions#>PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>PREFIX npdv: <http://sws.ifi.uio.no/vocab/npd#>PREFIX npdv2: <http://sws.ifi.uio.no/vocab/npd-v2#>PREFIX geos: <http://www.opengis.net/ont/geosparql#>SELECT * WHERE{ [] a w:Country ; w:hasName ?Name ; w:hasCountryPopulation ?Population ; } ORDER BY DESC(?Population) LIMIT 10" ;
  39.  
  40. sparqlQueryJson(query, endpoint, myCallback, false);
  41. var data = google.visualization.arrayToDataTable(resultArray);
  42.  
  43. var options = {
  44. title: document.selectionForm.graphName.value,
  45. hAxis: {title: 'Note: All Values are in thousands', titleTextStyle: {color: 'red'}}
  46.  
  47.  
  48. };
  49. if (item2 == 'bar'){
  50. var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
  51. chart.draw(data, options);}
  52. else if (item2 == 'pie'){
  53. var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  54. chart.draw(data, options);
  55. }
  56. else if (item2 == 'column'){
  57. var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
  58. chart.draw(data, options);
  59. }
  60.  
  61. }
  62.  
  63.  
  64. else if (item == 'query2')
  65. {
  66.  
  67. var data = google.visualization.arrayToDataTable(resultArray);
  68.  
  69. var options = {
  70. title: document.selectionForm.graphName.value,
  71. hAxis: {title: 'Note: All Values are in thousands', titleTextStyle: {color: 'red'}}
  72.  
  73.  
  74. };
  75. if (item2 == 'bar'){
  76. var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
  77. chart.draw(data, options);}
  78. else if (item2 == 'pie'){
  79. var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  80. chart.draw(data, options);
  81. }
  82. else if (item2 == 'column'){
  83. var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
  84. chart.draw(data, options);
  85. }
  86.  
  87. }
  88.  
  89. }
  90. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement