2

The user will input the data for the graph. I have used a drawline, but I cant get the location right. Here is my code so far. I cant use a bar chart libary, due to java enviroment being embeded into a webpage.

// Ex5-1: Weather Data Graph
enter code herevar canvas;
canvas = openGraphics();
var sun;
var n;
var xposition;
xposition = 40;
sun = prompt("enter the sun");
sun = parseInt(sun, 10);
 ///xposition= xposition +10;
canvas.drawLine(40, 10, 40, 245);
canvas.drawLine(40, 245, 390, 245);
canvas.drawString("225 ", 10, 30);
canvas.drawString("180 ", 10, 70);
canvas.drawString("135 ", 10, 110);
canvas.drawString("90 ", 10, 150);
canvas.drawString("45 ", 10, 190);
canvas.drawString("0 ", 10, 230);
canvas.drawString("J ", 50, 250);
canvas.drawString("F ", 80, 250);
canvas.drawString("M ", 110, 250);
canvas.drawString("A ", 140, 250);
canvas.drawString("M ", 170, 250);
canvas.drawString("J ", 200, 250);
canvas.drawString("J ", 230, 250);
canvas.drawString("A ", 260, 250);
canvas.drawString("S ", 290, 250);
canvas.drawString("O ", 320, 250);
canvas.drawString("N ", 350, 250);
canvas.drawString("D ", 380, 250);
canvas.setStroke(30);
canvas.drawLine(xposition, 230, xposition, sun);
canvas.paint();
Joseph
  • 117,725
  • 30
  • 181
  • 234
  • 1
    Java environment in the browser? Javascript has nothing to do with java? Or did you mean you have a java applet embedded in the web page? You can always look at http://d3js.org/ which is a handy javascript library for visualisations. – Stefan Pante May 10 '13 at 00:55
  • Agree with Stefan. You can even look to https://developers.google.com/chart/ – Madthew May 10 '13 at 00:58
  • It would help if we had access to drawString and drawLine – Travis J May 10 '13 at 01:09
  • You are asking a Java question, not a JavaScript question. See [this](http://www.roseindia.net/java/example/java/applet/CircleLine.shtml) for more information about the code you are trying to use. Read Wikipedia's [JavaScript](http://en.wikipedia.org/wiki/JavaScript) and [Java](http://en.wikipedia.org/wiki/Java) pages and browse [this SO page](http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java) to understand the difference between Java and JavaScript. Just because Java is running in a browser does not make it JavaScript. – AmbrosiaDevelopments May 10 '13 at 01:13
  • Sorry I can't use any libraries like jqplot, as I am creating the bar chart on a webpage which is Java-embedded, if that makes sense (hard to explain for me lol). I need to create a weather bar chart according to sunshine hours which have been given to me by my teacher, and then plot these sunshine hours for each month of the year on a bar chart (e.g. 30 hours for January on the chart, etc). I can only use whatever Javascript base code (I think it's JavaScript, it says this in the module guide provided) is available, so cannot bring any external libaries into the web page, just raw JavaScript. – user2368310 May 10 '13 at 01:38

1 Answers1

1

Unless you are writing this javascript bar chart plotter as an exercise, I would use jqplot.

jarmod
  • 71,565
  • 16
  • 115
  • 122
  • 1
    Sorry I can't use any libraries like jqplot, as I am creating the bar chart on a webpage which is Java-embedded, if that makes sense (hard to explain for me lol). I need to create a weather bar chart according to sunshine hours which have been given to me by my teacher, and then plot these sunshine hours for each month of the year on a bar chart (e.g. 30 hours for January on the chart, etc). I can only use whatever Javascript base code (I think it's JavaScript, it says this in the module guide provided) is available, so cannot bring any external libaries into the web page, just raw JavaScript. – user2368310 May 10 '13 at 01:25