Connections in electoral data – D3 and VBA follow on from oUseful post

Yesterday I showed how to do some data wrangling in VBA and Google Apps Script that Tony Hirst on his oUseful blog had done using scraperwiki, Open refine plus various APIs. Today he posted a quick analysis using gephi and scraperwiki on which candidates supported each other in a local Election.

Here’s how to do the same thing using VBA and D3.js.

The whole thing

I already have all the components – scraperwiki to Excel and creating d3.js force diagrams from Excel. So I just needed a couple of lines of code to pull it all together.

Public Sub ousefulSupportMashup()
    ' thanks to tony hirst for the data and method.
    ' http://blog.ouseful.info/2013/05/08/to-what-extent-do-candidates-support-each-other-redux-a-one-liner-thirty-second-route-to-the-info/


    Dim worksheetName As String, scraperName As String, sqlString As String
    worksheetName = "supportElection"
    scraperName = "iw_poll_notices_scrape"
   
 ' candidates that support each other
    sqlString = _
        "select * from support where support in (select candinit from support)"


    ' get data from Tony's scraperwiki and populate sheet -
    ' this time from the support table
    scraperWikiStuff scraperName, worksheetName, sqlString


    ' do a force d3.js diagram
    d3ForceDo worksheetName, "election force options", "election force fields"


End Sub

 

and here’s the result

You can see it live here

.. created from this data (candidates who supported other candidates) retrieved from scraperwiki

oh .. and of course we need to tweak a few parameters, as described in d3.js force diagrams from Excel.

 

Example

You can find the code by downloading the cDataSet.xlsm workbook from Excel liberation. It’s in the scraperWiki module,  the supportElection and d3allparameters tab.
About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.