View unanswered posts | View active topics It is currently Mon Dec 16, 2019 9:52 am






Reply to topic  [ 4 posts ] 
Bar graph from Array 
Author Message
Rookie

Joined: Tue Apr 28, 2015 4:01 pm
Posts: 2
Post Bar graph from Array
Hi there

I'm trying to output the data from an array of 61 integers into a bar graph, after a bit of research i've found the following command:

nxtFIllRect

But using this will an array outputs the following error: nxtFillRect(soundA);

**Error**:Array size mismatch. Call to 'nxtFillRect'. Parameter: 'const long Left' is 'soundA' of type 'long [61]'

How would I go out about putting said array into a bar graph?
Also, would there be any way to sort the data (e.g. ascending order) and then output it?

Cheers!

Connor


Tue Apr 28, 2015 4:06 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Bar graph from Array
I am afraid you'll have to give us more code than this. Could you attach it or paste it into a reply to this thread with [ code][/ code] tags (minus the spaces) around it?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Apr 29, 2015 1:33 am
Profile WWW
Rookie

Joined: Tue Apr 28, 2015 4:01 pm
Posts: 2
Post Re: Bar graph from Array
Sure sorry

The code that runs for a minute (takes a reading every second for 60 seconds) is as follows:

Code:
while(time1[T1] < 600)// while counter is under 60 seconds
   {
      lightValue = SensorValue[mylight]; // Assigns lightvalue to sensorValue
      soundValue = SensorValue[mysound];
      sonarValue = SensorValue[mysonar];

      lightA = SensorValue(mylight); // Assigns light array to sensorValue
      soundA = SensorValue(mysound);
      sonarA = SensorValue(mysonar);
         count++; // Adds one to the count value to store in different array
      wait10Msec(T1); // use a different sort of function to run count++ every second

      if(lightValue > highestlightValue){ // if light value is greater than highestvalue, overwrite highestvalue
         highestlightValue = lightValue;
      }
      if(lightValue < lowestlightValue){ // if light value is lower than lowestvalue, overwrite lowestvalue
         lowestlightValue = lightValue;
      }
      if(soundValue > highestsoundValue){
         highestsoundValue = soundValue;
      }
      if(soundValue < lowestsoundValue){
         lowestsoundValue = soundValue;
      }
      if(sonarValue > highestsonarValue){
         highestsonarValue = sonarValue;
      }
      if(sonarValue < lowestsonarValue){
         lowestsonarValue = sonarValue;
      }


Then when displaying the graphs, this is the code i've used:

Code:
if (nNxtButtonPressed == 1){
      eraseDisplay();
      nxtDisplayTextLine(1, "Loading Graphs...");
      // SORT GRAPH DATA HERE
      if (nNxtButtonPressed ==1){
         graphcount = graphcount + 1; //When button is pressed, increase counter by 1
         if (graphcount == 1){ // If counter at 1, display the unsorted sound graph
            nxtDisplayCenteredTextLine(1, "Sound");
            nxtFillRect (soundA);   //Import data from array
         }
         if (graphcount == 2){   // If counter at 2, display the unsorted sonar graph
            nxtDisplayCenteredTextLine(1, "Sonar");
            nxtFillRect (sonarA);   //Import data from array
         }
         if (graphcount == 3){   // If counter at 3, display the unsorted light graph
            nxtDisplayCenteredTextLine(1, "Light");
            nxtFillRect (lightA);   //Import data from array
         }
         if (graphcount == 4){   // If counter at 4, display the sorted sound graph
            nxtDisplayCenteredTextLine(1, "Sound Srt");
            nxtFillRect (soundA);   //Import data from array
         }
         if (graphcount == 5){   // If counter at 5, display the sorted sonar graph
            nxtDisplayCenteredTextLine(1, "Sonar Srt");
            nxtFillRect (sonarA);   //Import data from array
         }
         if (graphcount == 6){   //If counter at 5, cycle the counter back to one for the next press, display the acc sorted light graph
            nxtDisplayCenteredTextLine(1, "Light Srt");
            nxtFillRect (lightA);   //Import data from array
            graphcount == 1
         }
      }
      if (nNxtButtonPressed ==2){ //If centre button is pressed, exit the app
         stopAllTasks();
   }


Wed Apr 29, 2015 3:42 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Bar graph from Array
What do you think nxtFillRect() does? The function takes the following parameters:
Code:
nxtFillRect(Left, Top, Right, Bottom);

These are coordinates, not array values. You are going to have to iterate through your arrays and add sensor values one at a time:
for (int i = 0; i < [your array size]; i++)
Code:
{
  lightA[i] = SensorValue[mylight];  // note the square brackets!
}

Your code needs to be rewritten or it will never work.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Apr 29, 2015 3:55 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.