Big Data‎ > ‎

Graphs

<< back to BigData

Graphing Your Data - Using the Graph Widget


This is what we have so far:

              
 
We want to drag over the "Line Graph" widget  

               
         from 

          

to our card (make it larger to accommodate the graph)
  

If we double-click on the graph widget, we open up it's Property Inspector
Looking at the Data, we see the label are first (mon, tue, wed, etc for the x-axis), followed by the points (y-axis)
          

We have only 1 point for each county, so our data is simpler. If we delete the last two numbers on each line, we will get the graph for only 1 line. 
 The data for just 1 line will look something like this:


Each line has the x-axis label, then a comma (",") then the y-axis label for its point

So, we will add 2 buttons - 
  1 to graph by age and the other to graph by income.

For the "Graph Ages" button, we will go through each line and write out the county name and the age, separated by a comma and with a "return" at the end (to go to the next line)

our data should look like this:

Allegany County , 41.1
Anne Arundel County , 38.1
Baltimore City , 34.7
Baltimore County , 39.3
Calvert County , 40.7
Caroline County , 40
Carroll County , 42.7
Cecil County , 40.2
Charles County , 37.8


    So we just write out 

       1.  the county name (item #1 of the line) 
       2. a comma to separate them,
       3.  then the age(item #2 of the line),
       4. then a "return " to go to the next line


So, on the "Graph Ages" button, we have the following code: 

on mouseUp
    put empty into gData
    repeat with x = 2 to the number of lines of field "mydata"
        put (item 1 of line x of field "mydata" & "," & item 2 of line x of field "mydata" & return ) after gData
    end repeat
    set the graphData of widget "Line Graph" to gData
end mouseUp


We click on the button and it looks like this:


The only problem is that the counties are all run together at the bottom.
So, we have to shorten them by only using the first 8 characters of the names.

on mouseUp
    put empty into gData
    repeat with x = 2 to the number of lines of field "mydata"
        put (char 1 to 8 of item 1 of line x of field "mydata" & "," & item 2 of line x of field "mydata" & return ) after gData
    end repeat
    set the graphData of widget "Line Graph" to gData
end mouseUp

Our data should now look like this:

                             

And our graph looks like this:




So, on the "Graph Income" button, We write out the "county", a comma, then the "income" (item 3 of the line)

we have the following code: 

on mouseUp
    put empty into gData
    repeat with x = 2 to the number of lines of field "mydata"
        put (item 1 of line x of field "mydata" & "," & item 3 of line x of field "mydata" & return ) after gData
    end repeat
    set the graphData of widget "Line Graph" to gData
end mouseUp


We click on the button and it looks like this:



Now try the different sorts and see if the graphs make sense.


Comments