Data Visualization: Representing Information on Modern Web by Andy Kirk & Simon Timms & Andrew Rininsland & Swizec Teller

Data Visualization: Representing Information on Modern Web by Andy Kirk & Simon Timms & Andrew Rininsland & Swizec Teller

Author:Andy Kirk & Simon Timms & Andrew Rininsland & Swizec Teller [Kirk, Andy]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2016-09-30T04:00:00+00:00


Many of the questions on Stack Overflow have a large number of answers. The site is not optimized to show the latest answers; the answers are ranked by being the most accepted answer then randomly. This is done to give all answers a chance at being shown near the top which should, in theory, encourage people to vote for the best answer instead of just the first answer shown.

For this visualization, I would like to show how a question has been answered over time. Are more recent answers likely to get a higher score? Is the first answer always the best?

Let's start by pulling down the data for an individual question which has a large number of answers. To do this, we'll make use of the questions API. All of the API endpoints are hosted on https://api.stackexchange.com. We're going to make use of the latest API which is Version 2.1. This is also encoded into the URI, as is the specific endpoint and the ID. Within the question API, we're interested in the answers, so we can query specifically for them, giving us a URI of https://api.stackexchange.com/2.1/questions/{id}/answers.

In the query string, we'll specify the site against which we want to query. Stack Exchange hosts several dozen question and answer sites modeled on Stack Overflow, all of which are served from the same API endpoint, so it is necessary to filter just for Stack Overflow by passing in site=stackoverflow:

function retrieveQuestionAnswers(id){ var page = 1; var has_more = true; var results = []; while(has_more) { $.ajax(https://api.stackexchange.com/2.1/questions/ + id + "/answers?site=stackoverflow&page=" + page,{ success: function(json){ has_more = json.has_more; results = results.concat(json.items);}, failure: function() { has_more = false;}, async: false }); page++; } return results; }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.