Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
creating array of paragraph in javascript

I'm drawing data in a JS canvas. I need to enter the veritcal and horizontal axis values at fix intervals.

I would ask how to create an array of paragraph or text to assign an absolute coordinate and the right axis value to draw them around the canvas.

enter image description here

currently I created and edited line by line:

document.getElementById('percent0').innerHTML = 
                         a.toFixed(5-Math.round(Math.log10(a)));
a = minVal+(maxVal-minVal)*0.25;
document.getElementById('percent25').innerHTML =
                         a.toFixed(5-Math.round(Math.log10(a)));
a = minVal+(maxVal-minVal)*0.5;
document.getElementById('percent50').innerHTML = 
                         a.toFixed(5-Math.round(Math.log10(a)));
a = minVal+(maxVal-minVal)*0.75;
document.getElementById('percent75').innerHTML = 
                         a.toFixed(5-Math.round(Math.log10(a)));
a = minVal+(maxVal-minVal)*1;
document.getElementById('percent100').innerHTML = 
                         a.toFixed(5-Math.round(Math.log10(a)));

but I would like to use a smart way to do it with array if possible.

thks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just add mark values to array and use it where it changes:

const marks = [0, 25, 50, 75, 100};

marks.forEach(mark => {
const a = minVal+(maxVal-minVal)*mark / 100.0;
document.getElementById('percent' + mark).innerHTML =
a.toFixed(5-Math.round(Math.log10(a)));
});

If you want to create those html elements with code too you can simple have something like <div id="marks-container;></div> in your HTML and then add all paragraps with JS too -

const p = document.createElement('p');
p.id = "percent" + mark;
document.querySelector("#marks-container").appendChild(p);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!