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 6139825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:02:24+00:00 2026-05-23T18:02:24+00:00

I am drawing a histogram using an array of data (counts) and an array

  • 0

I am drawing a histogram using an array of data (counts) and an array to represent the histogram. I want to zoom into the data so that the number of points in the histogram is typically fewer than the data points that I have.

I need to map the data array to the histogram array such that when the histogram is exactly half the length of the data then each point is the sum of two data points, when it is 1.5 times then each histogram point is the sum of one data point plus half of the value of the next. Etc.

E.g

Data |2|3|1|2|2|3|4|1|
Hist | 5 | 3 | 5 | 5 |

Data | 2| 3| 1| 2| 2| 3| 4| 1|
Hist | 3.5|2.5| 3 |  4 | 4.5 |    

It seems like it could be a common problem (particularly for zooming images) but I have not found a library or function to do it. Does such as JavaScript thing exist?

  • 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-23T18:02:25+00:00Added an answer on May 23, 2026 at 6:02 pm

    This seems to be a pretty straight-forward algorithm:

    function get_hist(data, factor) {
        var hist = new Array();
    
        for(i=0; i<data.length; i+=factor) {
            el = get_hist_elem(data, i, factor);
            if(!isNaN(el))
                hist.push(el);
        }
    
        alert(hist.join(", "));
        return hist;
    }
    
    function get_hist_elem(data, start_pos, factor) {
        var int_start = (Math.floor(start_pos) == start_pos ? start_pos : Math.floor(start_pos) + 1);
        if(int_start > data.length)
            return NaN;
        var part_start = int_start - start_pos;
    
        var end_pos = start_pos + factor;
        var int_end = (Math.floor(end_pos) == end_pos ? end_pos : Math.floor(end_pos));
        var part_end = end_pos - int_end;
    
        var val = 0;
        for(j=int_start; j<int_end; j++)
            val += data[j];
        if(part_start > 0)
            val += data[int_start - 1] * part_start;
        if(part_end > 0)
            val += data[int_end] * part_end;
    
        return val;
    }
    

    And call it like this:

    var data = [2, 3, 1, 2, 2, 3, 4, 1];
    var factor = 1.5;
    var hist = get_hist(data, factor);
    

    I created a jsfiddle for you to play around with: http://jsfiddle.net/3RVKr/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using System.Drawing.Color, is there anything in Visual Studio that can display the color
I would like to draw histogram using matplotlib. However, due to the huge data(a
I'm drawing a histogram (custom data, not related to coloring) on an BufferedImage. And
When drawing arc segment using Core Graphics I noticed that zero angle is not
Drawing a blank on this, and google was not helpful. Want to make a
I'm working on drawing an SVG grid using Javascript. I've managed to get the
I'm doing custom drawing in datagridview cells and I have items that can vertically
I have a problem drawing something quickly in .NET. I don't think that any
I am drawing a grid and I want it to be larger than the
I'm drawing points on a map with OpenLayers like in this example: http://dev.openlayers.org/examples/draw-feature.html Now

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.