Developer information for Excel tables to d3.js Force diagramTo develop Excel applications that generate web pages incorporating d3.js force diagrams from Excel data, first read this Excel tables to d3.js Force diagram. You will also need to be familiar with How to use cDataSet and How to use cJobject This section will walk through the coding of a sample application. All the code for this can be found in the cDataSet.xlsm, downloadable from Downloads D3 ModuleThis contains examples of applications. d3ForceHereThis would normally be assigned to a button on the worksheet containing the table you want to chart. It creates a web using the data on this page, using the default parameter block names Public Sub d3forceHere() d3ForceDo End Sub d3ForceDoThis can be called with a specific worksheet name, and will run the e2e process on the data in the given worksheet Public Sub d3ForceDo(Optional wn As String = vbNullString, _ Optional optionName As String = "force options", Optional fieldName As String = "force fields") Dim w As String w = wn If w = vbNullString Then w = ActiveSheet.name End If mashupGeneral "d3allparameters", w, "force", optionName, fieldName End Sub mashupGeneralGiven a data worksheet name and parameter sheet name, it will run the end to end process and create and display a web page. Here are the main activities you can use a template
With .init(wholeSheet(params), , "fields", True, fieldName) ' validate stuff links = Split(.cell("links", "value").toString, ",") groups = Split(.cell("groups", "value").toString, ",") names = Split(.cell("names", "value").toString, ",") count = .cell("count", "value").toString styleColumn = .cell("styleColumn", "value").toString linkName = .cell("linkName", "value").toString labels = Split(.cell("count", "value").toString, ",") If arrayLength(labels) < 1 Then labels = names End If End With
.init wholeSheet(params), , item, True, item
With .init(wholeSheet(data), , "data", , , True) ' check everything exists Debug.Assert dsValidateHeadings(.headingRow, links) Debug.Assert dsValidateHeadings(.headingRow, groups) Debug.Assert dsValidateHeadings(.headingRow, labels) If count <> vbNullString Then Debug.Assert _ .headingRow.validate(True, count) If styleColumn <> vbNullString Then Debug.Assert _ .headingRow.validate(True, styleColumn) If linkName <> vbNullString Then Debug.Assert _ .headingRow.validate(True, linkName)
For Each dr In .rows ' add the nodes For i = LBound(links) To UBound(links) nodesLink.addNode _ fixup(dr, links(i)), _ fixup(dr, groups(i)), _ fixup(dr, labels(i)), _ fixup(dr, count) Next i ' make the links For i = LBound(links) To UBound(links) - 1 nodesLink.addLink _ dr.cell(links(i)).toString, _ dr.cell(links(i + 1)).toString, _ fixup(dr, count), _ fixup(dr, styleColumn), _ fixup(dr, linkName) Next i Next dr
mashD3ForceNow that we have the nodeLinks structure, and all the options we can serialize the data and options, and create the web page
https://gist.github.com/brucemcpherson/4684498 This generates this code from the test data in the sample workbook For the cNodesLinks object see the cDataSet.xlsm workbook. SummaryWhy not join our forum,follow the blog or follow me on twitter to ensure you get updates when they are available. in the meantime, see what else you can do with d3.js straight from Excel.
You want to learn Google Apps Script?Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, available All formats are available now from O'Reilly,Amazon and all good bookshops. You can also read a preview on O'Reilly. If you prefer Video style learning I also have two courses available. also published by O'Reilly. |
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > d3.js > Excel tables to d3.js Force diagram >