Help with creating axis & naming it

I am about to cry, I am so confused and lost. I’ve looked all over the resources but maybe my question is just too simple for it. I can’t figure out how to create and name an axis or how to create the little hash marks. image

This is my code so far:

JSONArray cats;
void setup(){
  JSONObject cat=cats.getJSONObject(0); //This tells processing to retrieve the first object in the cats array.
  String name=cat.getString("name");
  String breed=cat.getString("breed");
  int age=cat.getInt("age");
void draw(){
  text("madf graph",250,40); //the title 
  for(int i=0;i<cats.size();i++){
    JSONObject cat=cats.getJSONObject(i);
    int age=cat.getInt("age");
    String name=cat.getString("name");
    rect(i*30 + 80, 310, 30, -age*20);

Any guidance would be greatly appreciated.

1 Like

i would say for your graph area,

  • the axis are 2 lines();

  • the the name of the axis is some text("Age",x,y);
    at the end of the line

  • the numbers on the exis is text
    by a for loop
    for ( int i = 0; i<= 15; i+=5 ) text(i,x0,y0-i*20); // the 20 comes from your rectangle -age*20 info

1 Like

this line implicitly contains how you calculate the y position

So when you want to draw two text marks use the same y but other x (65 I guess)

Use 7 and 13 as age : text(“7”, 65, … );

Don’t use a for loop

1 Like

You can achieve anything if you work at it and persevere. I know this from experience.
Your codes so far is a good start.

This is a simple exercise.
Start working with lines and plotting them; the example shows plotting of rectangles and lines are much easier.
Notice that offsets (+80) and variables (-age*20) are used in plotting rectangle and can apply to lines.

rect(i*30 + 80, 350, 30, -age*20);

Add a background otherwise you keep redrawing over the screen and it looks worse.

Plot the lines and labels after the loop so you are not drawing them over each other unnecessarily.

I worked through this exercise and it is achievable for you:




The key concept to understand is that Processing is fairly low-level. It doesn’t have commands like “create and name an axis” – it has commands like “draw a line” – then you tell it where to draw the lines to make the axes, like you would with a pencil on paper.

If you want to create axes with higher-level commands, there are libraries – like Grafica – that do have higher-level things like axis commands for doing this: Default plot sketch - jagracar . However you have posted what looks like an exercise or homework assignment, so using a library is probably not the point of what you are learning – you are learning how to think through how to make the lines and hashes yourself, and where they go.