Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:02:25+00:00 2026-05-27T11:02:25+00:00

I am trying to do an exercise in data visualization using the browser to

  • 0

I am trying to do an exercise in data visualization using the browser to plot the contents of a local text file.
Both the html and the txt are local, and it is for prototyping/personal-use only.

Basically, I would want to use, say, javascript, to read a file just like this:

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
0.0, 0.2, 0.3, 0.3, 0.3, 0.2, 0.0
0.0, 0.3, 0.5, 0.6, 0.5, 0.3, 0.0
0.0, 0.3, 0.6, 0.8, 0.6, 0.3, 0.0
0.0, 0.3, 0.5, 0.6, 0.5, 0.3, 0.0
0.0, 0.2, 0.3, 0.3, 0.3, 0.2, 0.0
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0

and render as a square grid of colored circles. Each value from the txt would be the opacity of the correspondent circle, like this (made using Python, Numpy, Cairo and PIL):

enter image description here

I am a complete beginner on javascript and HTML5 Canvas, so I would appreciate very much a clue so as to what I should do, which functions to use, etc.

There’s no need to give complete code (but it would be nice!), just the name of the functions and concepts, so that I can look for tutorials and assemble my Frankenstein from a bunch of “Hello Worlds”, or anything like that.

Thanks for reading!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:02:26+00:00Added an answer on May 27, 2026 at 11:02 am

    TL;DR : http://bv.iriscouch.com/so/_design/ex/index.html and http://bv.iriscouch.com/so/_design/ex/separate-function.html

    This is a slightly verbose answer but I feel like I was in your shoes not too long ago, and would have benefitted from some of the below pointers. I will target it with Python analogies since you mentioned those Python libraries. Also feel like mentioning: I like low-level stuff, I love oscilloscopes, C, etc., but the beautiful, lower-level heart of javascript is its objects and functions — the browser environment is a jungle and I am much happier since handing off as much as possible to jQuery and Underscore.js.

    First, regarding csv format, if it’s an absolute requirement use something like d3.csv from the d3.js library. (In fact, regard all data vizualization javascript you learn from now forward as preparation for copying as much as possible from the imagination of Mike Bostock.) But asking about csv in Javascript is a bit like asking “I’m new to Asia, where is the best place to get sushi in Sichuan?” Answer: “You’re in Sichuan!!!“. Use json. In python in your case I would just do:

    >>> f = open('sample.csv').readlines()
    >>> rv = json.dumps([[float(i) for i in k.split(',')] for k in f])
    >>> file_out.write(rv)
    

    Here is how you do it in one piece: http://bv.iriscouch.com/so/_design/ex/index.html

    Here is how you might break it up into the core function that then gets rendered on the page’s canvas: http://bv.iriscouch.com/so/_design/ex/separate-function.html

    (Parenthetically, try iriscouch.com, it is one of the coolest things on the internet, and a good way to get familiar with Javascript. The below examples are there. sudo pip install couchapp, couchapp generate ex, cp *.js *.html ex/_attachments, cd ex && couchapp push https://user:pass@youraccount.iriscouch.com/somename is how I put up these examples, totally free. Windows installer here.)

    If you want to look at the underlying data as reformatted, that’s here.

    Finally, you can see more of my personal babysteps in this stuff at http://aguacat.es

    Inline of above example:

    <!doctype html>
    
    <html>
      <head>
        <script src="jquery.js"></script>
      </head>
      <body>
        <canvas id="circles" height="700" width="700"></canvas>
        <script>
          // $ is just a function. It makes dealing with the
          // browser itself less annoying. Call it with a
          // function as argument. The function has no
          // name, like a python lambda, and it will
          // request the json and process it.
          $(function () {
            var the_color = "rgba(0,0,255,alpha_token)";
            // ask for the json and register the following
            // function (second argument to getJSON) to be called 
            // once it is delivered:
            $.getJSON('json_from_csv.json', function(data) {
              // no more jquery for now
              var canvas = document.getElementById("circles");
              // you declare these to avoid them being global variables:
              var h, w, column_width, column_height, x_pos, y_pos, radius;
              h = canvas.height;
              w = canvas.width;
              column_width = w / data[0].length;
              column_height = h / data.length;
              // we're working in 2 dimensions:
              var context = canvas.getContext('2d');
              radius = column_width / 2; 
              data.forEach(function (row, row_index) {
                row.forEach(function (entry, column_index) {
                  x_pos = column_index * column_width + radius;
                  y_pos = row_index * column_height + radius;
                  context.moveTo(x_pos, y_pos);
                  context.beginPath();
                  context.arc(x_pos, y_pos, radius, 0, Math.PI*2)
                  context.fillStyle = the_color.replace(/alpha_token/, entry);
                  context.strokeStyle = the_color.replace(/alpha_token/, entry);
                  context.fill();
                  context.stroke();
                  context.closePath();
                });
              });
              });
            });
          </script>
        </body>
    
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a simple exercise querying a database from JS using XMLHTTPrequest
I'm working on a gym logging app using Core Data model. I'm trying to
I'm trying to create a static file server in nodejs more as an exercise
I'm trying to create a logger for a GWT application as an exercise to
I'm trying to learn scheme via SICP. Exercise 1.3 reads as follow: Define a
I'm trying to teach myself C++, and I'm going through a basic exercise about
I'm new to C and I'm trying to solve one of the exercise problem
I'm brand new to MVC and, as a learning exercise, I'm trying to re-write
I am trying to populate a UITableView with data from json result. I can
I'm trying to implement some functionality of BigInteger s as a personal programming exercise.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.