Change bar colors for each IGRAPH bar chart with only an x-axis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 'Resolution number: 41959 Created On: Mar 4 2004 'Product Family: SPSS Version: 'Problem Subject: Script To change bar colors For Each IGraph bar chart that only contains an x-axis variable 'Problem Description: I am using SPSS For Windows. I have an SPSS Output file that 'contains both Pivot Tables And IGraphs. For Each IGraph bar chart that only contains 'an x-axis variable, I would Like To change the bar color. How can I Do so automatically? 'Resolution Subject: The following script should assist you 'Resolution Description: 'The following script should assist you. Highlight the script below And click Edit->Copy. 'Next, click File->New->Script. Click Cancel. Delete Any visible Text. Click Edit->Paste. 'Next, click File->Save As And save the script using a Name such As, 'ChangeBarColors.sbs'. 'Exit the script window. 'In the Output window, make sure you at least have one IGraph that contains only an x-axis 'variable. Click Utilities->Run Script. Locate the saved script. Click Run. You should notice 'that For Each IGraph bar chart that contains only an x-axis variable, the bar chart color 'has been changed To green. For Any IGraph bar chart that contains a Legend variable, the 'bar colors have Not been changed. 'Read through the script For how To modify it To change bars To your desired color. '______________________________________________________________________________________ 'Begin Description 'This script will cycle through the output items 'of the currently open SPSS output 'For each IGraph bar chart found, the script will check to see that it only 'contains an x-axis variable 'The script will then change the bar color as specified in the script 'End Description Option Explicit Sub Main Dim objOutputDoc As ISpssOutputDoc Dim objOutputItems As ISpssItems Dim objOutputItem As ISpssItem Dim objSPSSIGraph As ISpssIGraph Dim objIgraph As ISpssIGraph Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc 'We get Output Items and loop through to find each IGraph Set objOutputItems = objOutputDoc.Items() Dim intItemCount As Integer For intItemCount = 0 To objOutputItems.Count - 1 Set objOutputItem = objOutputItems.GetItem(intItemCount) If objOutputItem.SPSSType = SPSSIGraph Then Set objIgraph = objOutputItem.Activate Set objIgraph = objOutputItem.GetIGraphOleObject Call ChangeBarColors (objIgraph) objOutputItem.Deactivate End If Next End Sub Sub ChangeBarColors (objIgraph As ISpssIGraph) Dim I As Integer Dim objBar As ISpssIGraphBarElement Dim MyArea As ISpssIGraphArea Dim objVariableManager As ISpssIGraphVariablesMgr Set objVariableManager = objIgraph.VariablesMgr With objVariableManager For I = 0 To objIgraph.Elements.Count - 1 'here we check to see that there is not a legend variable If .IsAssigned(SpssIGraphColor) = False And .IsAssigned(SpssIGraphStyle)= False Then If objIgraph.Elements.Item(I).Type = SpssIGraphBar Then Set objBar = objIgraph.Elements.Item(I) Set MyArea=objBar.GetArea With MyArea 'here we change the bar color to green 'use the chart below to replace the code 'values for a different color .BackgroundColor = RGB(0,255,0) 'Color code below 'RGB values follow the color name 'Black 0, 0, 0 'Blue 0, 0, 255 'Cyan 0, 255, 255 'Green 0, 255, 0 'Magenta 255, 0, 255 'Red 255, 0, 0 'White 255, 255, 255 'Yellow 255, 255, 0 End With End If objIgraph.Redraw End If Next End With End Sub |
Related pages
...
Navigate from here