All the information is asked for. so the number of values is unknown, the data points are unknown and so forth. this is what i have thus far... -
var array = userValues;
-
maximumValue(array);
-
var maxRows = max;
-
var maxCols = valuesToPlot.length;
-
var secondArray = createTwoDimArray(maxRows, maxCols);
-
-
the number of values and the datas points have been stored in the userValues array.
7 3911
Can you please elaborate the problem you are facing with this code?
Thanks and Regards
Ramanan Kalirajan
I don't know how/what to do next.
for example: given 5 entries with the following data points [2,3, 4, 5, 6] we are suppose to make a vertical histogram using functions made [maximum value of array and createTwoDimensionalArray]
gits 5,390
Expert Mod 4TB
given that the array would be:
the output should look like: -
2 * *
-
1 * * * * *
-
0 1 2 3 4 5 6
-
or what should be produced?
kind regards
given that the array would be
[2,2,3,4,5,5,6]
the output would be
**
**
***
****
*****
*****
******
but vertical.. once vertical, reading from left to right there is a positive slope
gits 5,390
Expert Mod 4TB
so basicly you need to sort the array ascending and then transform it to a 'vertical' structure ... that would mean you could do something like the following steps:
1. sort the array - have a look at the array's sort() method
2. the last value in the array should then be the max
now you could produce: - a0 = [' ', ... , '*']; // where the length == length of the base array
-
...
-
an = ['*', ... , '*']; // where n == max value of the base array
-
then display a0 ... an linewise on the page ... for a simple line concat for every array you might use the join()-method.
kind regards
it doesnt have to be ascending though and I am not allowed to use join method or any method.
i am having problems in creating the two dimensional array right now to create the histogram.
this is what i have so far -
-
-
function createTwoDimArray(maxRows, maxCols) {
-
var newArray = new Array(maxRows);
-
for (var row=0; row<maxRows; row++) {
-
newArray[row] = new Array(maxCols);
-
}
-
return newArray;
-
}
-
-
-
function createArrayVerticalGraph(valuesToPlot, symbol) {
-
var array = valuesToPlot;
-
var maxRows = maximumValue(array);
-
var maxCols = valuesToPlot.length;
-
var secArray = createTwoDimArray(maxRows, maxCols);
-
var secArray = newArray[row];
-
var row = (maxRows - 1);
-
for (col = 0; col < secArray[row].length; col++) {
-
for (value = valuesToPlot[col]; value > 0; value--) {
-
secArray[row][col] = symbol;
-
row--;
-
}
-
}
-
return secArray;
-
}
-
-
-
gits 5,390
Expert Mod 4TB
basicly it could look like this - i just use the document.write() method for simplicity ... it shouldn't be used in reality for such purposes: - var a = [2,2,3,7,4,5,6];
-
-
function createPlotArray(a) {
-
var plotArray = [];
-
var plotArrayLength = 0;
-
-
var check = function(arr, max) {
-
var ret = [];
-
-
for (var k = 0, l = arr.length; k < l; ++k) {
-
var r = arr[k];
-
var val = r >= max ? '*' : ' ';
-
ret.push(val);
-
}
-
-
return ret;
-
};
-
-
for (var i = 0, l = a.length; i < l; ++i) {
-
if (a[i] > plotArrayLength) {
-
plotArrayLength = max = a[i];
-
}
-
}
-
-
for (var j = 0; j < plotArrayLength; ++j) {
-
plotArray.push(check(a, max).join(''));
-
max--;
-
}
-
-
return plotArray;
-
}
-
-
var p = createPlotArray(a);
-
-
document.write('<pre>');
-
-
for (var i = 0, l = p.length; i < l; ++i) {
-
document.write(p[i] + '<br/>');
-
}
-
-
document.write('</pre>');
-
when you need to avoid the join() then use an iteration for that step.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Oracle3001 |
last post by:
Hi All, I am trying to use JAI to build a histogram of an image i have. I
have posted the code below, and the error I get at runtime. I have taken the
code from the offical java examples, so I am...
|
by: ext_u |
last post by:
Ok I thought I would try to take the program one thing at a time. (If
you remember my last post I am trying to make a histogram with data on
the size of each word)
Anways first .. I obviously...
|
by: P2P |
last post by:
Hi
Does anyone know a simple cross-broswers vertical scrolling javascript
that can call up its scrolling contents off an external html page/file?
Much appreciated
--
P2P...
|
by: Greg |
last post by:
I'm guessing the problem I'm having has something to do with Master Pages or
DetailsView because the exact same code works fine on a page without a Master
Page and DetailsView controls.
The...
|
by: c19h28o2 |
last post by:
Hi,
Guy's I know there are several posts about this, however I do not want
to read them as answers are undoubtedly posted!
Here is my attempt but I'm slightly stuck. I'm not looking for the...
|
by: arnuld |
last post by:
i was able to create a solution for a Horizontal-Histogram. i was
completely unable to understand this Vertical-Histogram phenomenon.
even though i have looked at the solution at this page:
...
|
by: sindhu |
last post by:
Hello
please some one tell me how to make a menu appear horizontal or vertical in javascript and css.
I'm bugged up after searching for one factor that makkes a menu8 appear horizontal or vertical...
|
by: zaturn |
last post by:
To student:
The this the new assignment.
Ex7 VERTICAL HISTOGRAM
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |