d3.sparql - How to query SPARQL endpoints directly from D3js?
Asked Answered
L

3

11

I like to get visuals based on RDF data from a SPARQL endpoint. It would be a nice addition to d3 to get an additional external data loader which can pull data by issuing SPARQL queries.

Did already someone work on something like this? Any pointers for such an enterprise? Or a completly obvious solution I did overlook?

Lunn answered 8/3, 2013 at 15:58 Comment(0)
L
3

I finally came around to create a d3-sparql plugin which is build according the d3 v4 plugin architecture. (A d3 v3 version is also available.)

Download and add the plugin to your project:

<script src="d3-sparql.min.js"></script>

Specify the endpoint and *query" to get the data prepared for use in a d3 visualization:

d3.sparql(endpoint, query, function (error, data) {
  console.log(data);
}

The plugin also does cast the RDF datatype in the JavaScript equivalents Date() and Number().

Lunn answered 1/8, 2017 at 14:54 Comment(1)
There exists also sgvizler.Lyonnaise
U
10

There is the d3sparql project that actually enables to create d3 visualizations from the results of a SPARQL query.

Here is how it self-describes:

JavaScript natually fits for querying a SPARQL endpoint which provides a REST service returning the result in the JSON format. The d3sparql.js library provides functions executing a SPARQL query by Ajax call (XMLHttpRequest) and visulaizing results by the D3 library. Basically, this library transforms the SPARQL Query Results JSON Format (aka. application/sparql-results+json) into several JSON formats which major D3 layouts can accept. Many of the examples are borrowed from bl.ocks.org and bost.ocks.org.

Home page: http://biohackathon.org/d3sparql/

Source code: https://github.com/ktym/d3sparql

Undertaker answered 14/1, 2015 at 18:55 Comment(1)
Awesome! About time. (-,Lunn
H
5

First of all, me too! I definitely would like to see that SPARQL query feature (any RDF or SPARQL feature actually) in d3. To my knowledge, nothing like that exists.

So for now: Take a look at this question to see how to use jQuery to access SPARQL endpoints.

Also, you might want to learn more about the same origin policy and how to circumvent it using JSONP. This article at IBM developerWorks serves as a good introduction.

And it might be interesting to take a look at the implementation of sgvizler.js (source).

Hasten answered 9/3, 2013 at 12:24 Comment(2)
I currently use sgvizler.js to get the job done. Works not to bad, except the d3 script waits until the SPARQL endpoint answers. It would be great to get the sgvizler SPARQL query code directly into d3.Lunn
I see! Interesting. Sorry, I assumed less knowledge/experience on your site. What kind of project are you working on? Can we see it somewhere?Hasten
L
3

I finally came around to create a d3-sparql plugin which is build according the d3 v4 plugin architecture. (A d3 v3 version is also available.)

Download and add the plugin to your project:

<script src="d3-sparql.min.js"></script>

Specify the endpoint and *query" to get the data prepared for use in a d3 visualization:

d3.sparql(endpoint, query, function (error, data) {
  console.log(data);
}

The plugin also does cast the RDF datatype in the JavaScript equivalents Date() and Number().

Lunn answered 1/8, 2017 at 14:54 Comment(1)
There exists also sgvizler.Lyonnaise

© 2022 - 2024 — McMap. All rights reserved.