We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Visualizing Data question
Page Index Toggle Pages: 1
Visualizing Data question (Read 819 times)
Visualizing Data question
Jun 13th, 2008, 6:41pm
 
I have been working through the tutorials in Visualizing Data, and it's been a great resource. After completing each one I feel like an expert!  But now, I'm trying to start branching out and doing my own code, it isn't quite as smooth...

My question is very simple, but I can't seem to find any resources to answer and figure it out. I have imported a database and want a chart to be created very similar to the Milk-tea-coffee database. The difference is that I want to also separate by month, not just years in the display.

My data is in the form:

Year, Month, Milk
2003, 1, 35

Using the example from the book, the data is all stacked up as points within each year, one on top of another. I'd really like to figure out the logic and approach to solving this simple problem. How do I interpolate the 12 months of the year in between each year?  Also, how do I prevent the Month column from being displayed as part of the chart?

I know I could probably do some ugly hack, like changing the data to a running number for months and generate a decent looking chart, but I'd like to understand the "proper" way to approach a problem like this. It seems like something that divides or lists the points between 0 and 11 within each year would do it, but I just can't make the connection into how to go about setting up an array like that.

I have searched through the forums quite a bit, but with the keywords "month" or "year" it's really hard to find relevant info, here or through the web in general. Thanks in advance for any guidance, and particularly for an explanation of the rationale behind the approach.

Cheers,

Bryan
Re: Visualizing Data question
Reply #1 - Jun 13th, 2008, 7:05pm
 
Glad to hear from someone who's working through the examples. For your new sketch, a few questions:

In the end, how are you planning to show the data, and what are you trying to learn from it? Are you looking for trends over the course of several months/years, or are you looking to compare cyclic trends (e.g. overlay each year so you can compare January 2003 vs. January 2004 and 2005).

Also, does that data begin and end cleanly in January of one year and December of another?
Re: Visualizing Data question
Reply #2 - Jun 13th, 2008, 7:42pm
 
I am wanting to see trends over several years on a month by month basis. Pretty similar to the example in the book, but a different time structure. I already massaged the data extensively, so yes, it has 12 months in each year. Some fields did not have transactions in all 12 months though..

Once I get through this part,  I would like to overlay the data in various ways. For example, March 2003 had a total of X transactions, within that X there are about 5 kinds of transactions, it would be interesting to compare trends in the kinds of transaction over time. Are certain transactions trending up or down as a part of the total? I would imagine a vertical bar with color coded sections would be ideal, but I'd like to just alter the line graph and see it working with my data and then move on from there.

Thanks for the help, the book is definitely a lot of fun to go through. I'm definitely interested in Processing from the Artist point of view, and I was able to follow it well.

To me, it's like learning to paint or play an instrument, there is a skill set that you need before you can get creative with the code and that's where I'm still working. I know this is a pretty basic chart problem, but I feel as I am able to understand the approach I'll start to get better at coming up with my own ideas.
Re: Visualizing Data question
Reply #3 - Jun 14th, 2008, 6:55pm
 
I did figure out my problem, I created a new float and used math to generate an X distance to the next volumeInterval -    float p=(coltype-1)*7.3

I changed the "7.3" to visually line up with where 12 months seemed to fall in my layout and it seemed to work. I'm sure there is better math that could do it more accurately. If anyone else is interested in this same kind of problem, here's the code I used below. I also added a rollover with the month converted to the actual name.


//draw the data as a series of points
void drawDataPoints(int col){
 for (int row=0; row<rowCount;row++) {
   float coltype = data.getFloat(row,0);
   int coli = int(coltype);
   float p=(coltype-1)*7.3;
   if (data.isValid(row,col)) {
     float value = data.getFloat(row,col);
     float x = map(years[row], yearMin, yearMax, plotX1, plotX2);
     float y = map(value, dataMin, dataMax, plotY2, plotY1);
     point (x+p,y);
 
 String monthNames="";
 if (coli==1){
   monthNames = "January"; // happiness
 }
 
else if (coli==2){
   monthNames = "February";
 }
 
  else if (coli==3){
   monthNames = "March";
 }
 
  else if (coli==4){
   monthNames = "April";
 }
  else if (coli==5){
   monthNames = "May";
 }
  else if (coli==6){
   monthNames = "June";
 }
  else if (coli==7){
   monthNames = "July";
 }
  else if (coli==8){
   monthNames = "August";
 }
  else if (coli==9){
   monthNames = "September";
 }
  else if (coli==10){
   monthNames = "October";
 }
  else if (coli==11){
   monthNames = "November";
 }
  else if (coli==12){
   monthNames = "December";
 }
 
 
  float d = dist(x+p,y,mouseX,mouseY);  
 
       if((d<5) && (d < closestDist)) {
         closestDist = d;
         closestText = monthNames + "\n$" + value;
         closestTextX = x + p;
         closestTextY = y-40;
       }
   }
 }

Re: Visualizing Data question
Reply #4 - Jun 15th, 2008, 1:01pm
 
Just a small recommendation - use class java.text.DateFormatSymbols in order to simplify and localize the month name determination, as in
Code:
import java.text.DateFormatSymbols;

// ...

DateFormatSymbols symbols = new DateFormatSymbols();
String[] months = symbols.getMonths();
String monthNames = months[coli - 1];


/Rick
Page Index Toggle Pages: 1