Yes VIrginia You Can Script Bar Charts in DesktopX
Or more aptly proof of concept of scripting bar charts
Thursday, April 5, 2007 by SirSmiley | Discussion: DesktopX

- ShowChart Array(6, 10, 12, 18, 23), Array("P1", "P2", "P3", "P4", "P5"), "This is the Chart Title", "X Axis Label", "Y Axis Label"
- Sub ShowChart(ByRef aValues, ByRef aLabels, ByRef strTitle, ByRef strXAxisLabel, ByRef strYAxisLabel)
- ' Some user changable graph defining constants
- ' All units are in screen pixels
- Const GRAPH_WIDTH = 300 ' The width of the body of the graph
- Const GRAPH_HEIGHT = 200 ' The height of the body of the graph
- Const GRAPH_BORDER = 2 ' The size of the black border
- Const GRAPH_SPACER = 5 ' The size of the space between the bars
- ' Debugging constant so I can easily switch on borders in case
- ' the tables get messed up. Should be left at zero unless you're
- ' trying to figure out which table cells doing what.
- Const TABLE_BORDER = 0
- 'Const TABLE_BORDER = 10
- ' Declare our variables
- Dim I
- Dim iMaxValue
- Dim iBarWidth
- Dim iBarHeight
- ' Get the maximum value in the data set
- iMaxValue = 0
- For I = 0 To UBound(aValues)
- If iMaxValue < aValues(I) Then iMaxValue = aValues(I)
- Next 'I
- 'Response.Write iMaxValue ' Debugging line
- iBarWidth ="20"
- ' Calculate the width of the bars
- ' Take the overall width and divide by number of items and round down.
- ' I then reduce it by the size of the spacer so the end result
- ' should be GRAPH_WIDTH or less!
- 'iBarWidth = (GRAPH_WIDTH \ (UBound(aValues) + 1)) - GRAPH_SPACER
- 'Response.Write iBarWidth ' Debugging line
- ' Start drawing the graph
- DesktopX.Object("lbl.ChartTitle").Text = strTitle
- DesktopX.Object("lbl.Yaxis").Text = strYAxisLabel
- DesktopX.Object("lbl.Yaxis").Rotation = -90
- ' <TD ROWSPAN="2"><IMG SRC="./images/spacer.gif" BORDER="0" WIDTH="1" HEIGHT="<%= GRAPH_HEIGHT %>"></TD>
- ' <TD VALIGN="top" ALIGN="right"><%= iMaxValue %> </TD>
- DesktopX.Object("obj.Yline").Width = GRAPH_BORDER
- DesktopX.Object("obj.Yline").Height= GRAPH_HEIGHT
- ' We're now in the body of the chart. Loop through the data showing the bars!
- For I = 0 To UBound(aValues)
- iBarHeight = Int((aValues(I) / iMaxValue) * GRAPH_HEIGHT)
- '-Clones bars
- If b = False Then
- Dim z, strname
- z=0
- Do
- z = z+1
- strname = "bar" & z
- Loop until DesktopX.IsObject(strname)=False
- DesktopX.object("bar0").Clone strname, DesktopX.object("bar"&(z-1)).Left + iBarWidth + GRAPH_SPACER, DesktopX.object("bar0").Bottom-iBarHeight
- DesktopX.object("bar"&(z)).Width = iBarWidth
- DesktopX.object("bar"&(z)).Height =iBarHeight' %>" ALT="<%= aValues(I) %>"></TD>
- DesktopX.object("bar"&(z)).Visible = True
- End If
- Next 'I
- ' </TR>
- ' <!-- I was using GRAPH_BORDER + GRAPH_WIDTH but it was moving the last x axis label -->
- ' <TR>
- ' <TD COLSPAN="<%= (2 * (UBound(aValues) + 1)) + 1 %>"><IMG SRC="./images/spacer_black.gif" BORDER="0" WIDTH="<%= GRAPH_BORDER + ((UBound(aValues) + 1) * (iBarWidth + GRAPH_SPACER)) %>" HEIGHT="<%= GRAPH_BORDER %>"></TD>
- ' </TR>
- ' The label array is optional and is really only useful for small data sets with very short labels! %>;
- ' If IsArray(aLabels) Then
- ' For I = 0 To UBound(aValues)
- ' = aLabels(I)
- ' Next 'I
- DesktopX.Object("lbl.Xaxis").Text = strXAxisLabel
- End Sub
- '--Clears Chart
- Function dxNewChart
- Object.SetTimer 100, 100
- End Function
- Sub Object_OnTimer100
- Call clearChart
- End Sub
- Function clearChart
- Dim i, strname
- i=0
- Do
- i = i+1
- strname = "bar" & i
- Loop until DesktopX.IsObject(strname)=False
- If i > 1 Then
- DesktopX.object("bar" & (i-1)).delete
- Else
- Object.KillTimer 100
- End If
- End Function
- '--End Clears
Reply #2 Thursday, April 5, 2007 11:56 PM
One immediate thought of using it would be something like Vad's Gallery Checker. Instead of displaying numbers you could display bars(numbers as labels) or a stacked bar chart with the second criteria being downloads today. They have a stacked bar chart script but, I want to get a handle on this then release into into the Scripts Gallery.
Reply #3 Saturday, April 7, 2007 9:29 AM
Some more ideas for usage:
- Poll Results streamed to your desktop
- Task/Project Status

Reply #4 Saturday, April 7, 2007 12:54 PM
Can you comment on where the values are getting pulled from?
WIll data be able to be pulled from sources like Google Spreadsheet?
Reply #5 Saturday, April 7, 2007 4:58 PM
- ShowChart Array(6, 10, 12, 18, 23), Array("P1", "P2", "P3", "P4", "P5"), "This is the Chart Title", "X Axis Label", "Y Axis Label"
The first being the values, the second being the labels, then the respective titles.
To answer your question; yes, you could pull data from the google spreadsheet. My immediate thinking is setting it up in a preferences menu, or a read from csv, databse, excel or xml.
Reply #7 Saturday, April 7, 2007 5:08 PM
Reply #8 Thursday, April 12, 2007 4:54 PM
This is really great, need to see what can be done with it.
Reply #9 Thursday, April 12, 2007 5:56 PM

Reply #10 Wednesday, April 18, 2007 12:42 PM
Here's the features I'm working on.
-Sizable
-Horizontal/Vertical Option
-Legend that can be positioned right,left,up,down
-Dynamic chart (within limitations. eg. maximum of say 10?)
Here's a pic of something I've done for myself. It's based on fixed array dynamically updated via timer.

Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Thursday, April 5, 2007 11:14 PM
Ummm . . how the hell does it work, what's it do? How can I use it?
(Thanks for sharing!!)