This is the second part of a three-part post on how to create a Visio shape that displays multiple colours based on linked data within an Excel workbook...
The linking Visio to Excel data is basically the same as a previous post (Linking size data to shapes), but I’ll repeat most of it here for completeness.
If you want to download an example then I've zipped up a sample Excel and Visio document here.
Excel Walkthrough – creating the data
- Create your data in Excel making a note of the column names – I’ll come back to this in a moment.
- Optionally, you can select the table you’ve created and define a named range as follows:
3. Save and close you workbook.
Visio Walkthrough – Data Graphics
The objective here is to create four child shapes that you’ll group together into a single shape once the Data Graphics have been applied.
- Create a new blank document in Visio.
- Select the Rectangle tool (Ctrl + 8) draw a shape to the size you require (remember there’s going to be four of these).
- Right click on the shape and select Show ShapeSheet. If it’s not visible then check ‘Run in developer mode’ is checked under File [tab] / Options / Advanced. (See this Just for starters post for an introduction to the ShapeSheet).
- On the ShapeSheet Design tab click Insert in the Sections group and tick the Shape Data checkbox followed by the OK button.
- In the new Shape Data section rename Prop.Row_1 to Prop.Data and set its Type cell to 2.
- Scroll down to the Protection section and set the LockFromGroupFormat to 1.
- Close the ShapeSheet.
- With the shape selected, press Ctrl + D three times to create the other shapes and arrange them horizontally or as required.
- Now select the first shape again and, from the Data ribbon tab, select Data Graphics / Create New Data Graphic…
- In the resulting two dialogs set the fields as the image below:
- Click OK to the two dialogs again and Yes from the following message to apply the Data Graphics to the selected shape.
- Check that you’re happy with result. If you are, then select the next shape and repeat steps 9 to 11. Remember to create new Data Graphics for each shape and don’t be tempted to apply old existing ones you’ve just created. (If you’re not happy then you can go back and hit the Edit item button to modify the criteria and colours.)
- Now select all four shapes and hit Shift + Ctrl + G to group the shapes together.
Let’s break there for a second and have a quick look at the sub-shapes’ ShapeSheet to see what’s happened.
There’s some interesting points to note:
- In the ShapeTransform section you can see that the shape has been given a size relative to its parent, the group shape. In the case above this tells you that the ID of the group shape is 9.
- User.visDGCBVFill is one of the cells generated by Visio’s Data Graphics Color By Value functionality. It does something very similar to my User.CalculatedColor cell I described in the previous post.
- User.visDGDisplayFormat is a reference to the Data Graphics master shape that was generated as part of step 9. As you created four Data Graphics, there are now four corresponding hidden masters (although you can see them in the drawing explorer).
- In the Fill Format section, you can see that the FillForegnd cell references the User.visDGCBVFill cell and so the link to the calculated colour is complete.
Visio Walkthrough – group shape wiring
Ok, so you’ve now created a group shape that contains the four Color By Value child shapes. You now need connect the Excel data to the document and wire up some data linked group shape cells with the children.
- Select Data [tab] / Link data to shapes… , and select the Excel workbook you created earlier using the first two screens of the wizard.
- In the third screen of the wizard, select the Named range that you created in Excel, followed by the Finish button to exit the wizard. (Note you can of course click next to modify the default settings.)
- You should now be returned to the main window in Visio with the External Data window visible and displaying your data.
- Select your new group shape, right click to display the ShapeSheet.
- On the ShapeSheet Design tab click Insert in the Sections group and tick the Shape Data checkbox followed by the OK button.
- Select the Prop.Row_1 cell and click Insert, from the Rows group, three times to add some new Shape Data rows.
- For each Shape Data row, set the Label cell to the corresponding Column title in the External Data window. So Prop.Row_1.Label should be set to “Values1”, Prop.Row_2.Label should be set to “Values2” and so on.
- For each Shape Data row, set the Type cell to 2.
- Now the Shape Data rows are in place on the group shape they’re available to reference from the sub shapes. So sub-select the first child rectangle shape, right-click and open its ShapeSheet.
- In the Value cell of Prop.Data row, add the formula to reference the correct Shape Data cell in the parent. For example, in the first rectangle the formula would be =Sheet.9!Prop.Row_1 (where 9 is the ID of the group shape).
- Repeat steps 9 and 10 for each of the other sub-shapes.
Visio Walkthrough – creating a master shape
You should now have a shape that’s ready to be turned into a master, although it’s always good to have a backup so you should start the next stage by creating a duplicate.
- Select your group shape and hit Ctrl + D to create a duplicate shape.
- If the Document Stencil isn’t already visible you can show it by clicking on More Shapes / Show Document Stencil in the Shapes window – it’s the last one in the list.
- Drag and drop your new shape into the Document Stencil.
- Right click on the new master and select Edit Master / Master Properties.
- Rename your master to whatever you want (in my case ‘MultiCBV’), tick the Match master by name on drop checkbox and click OK.
- You should now have a single master visible in the Document Stencil, plus four other (Data Graphic) ones represented in the Drawing Explorer. It should look something like this:
- Before you drop your linked shapes, just check that the Apply after Linking Data to Shapes option, under Data [tab] / Data Graphics is not ticked.
- Now, with your master shape selected in the Document stencil, select one or more rows in the External Data window and drag and drop them on the page to drop your data-linked shapes.
So finally, you should have arrived at a page with four ‘data-linked-data-graphicked’ (no, it’s not in my dictionary either) shapes:
In the last part of this post I’m going to look at how you go about maintaining and changing both the colours and logic criteria.