[live code here – each time you click run, you’ll get a new random walk as the dataset]
One of the cool side-effects of creating graphs from scratch is having to really think about what defines a particular graph or function. Today was about the histogram!
Ignore the terrible color choices and lack of labels. Better things will come in time. The left chart are the values of the random walk. Red highlights areas of significant change. On the right is a histogram of the values. Pink is negative bins and grey are positive. I’m currently using a bin width of 7. There are 1000 values, with a start point of zero and a maximum step between points of 5.
I actually wrote three slightly different functions for binning, all based on the suggestion here. The main challenge was what I wanted to do with the bin & value information once I had it. Put it in an array? In an object? In an array of objects? If you click on the super tiny picture below, you can see the three ways I was considering storing the data. While it made the histogram function a little less elegant, I eventually opted for the array of objects in order to make it easy to create the chart (test2 in the picture). Deciding how to store the data was a great exercise in getting to know arrays vs objects more intimately. Sending out a thank you to my colleague Cesar for helping me think through the options!
Three versions below (click to enlarge):