-1

I'm currently using a d3.js graph which is written in javascript. You can find the original graph here (view the source to see the javascript coding): http://mbostock.github.io/d3/talk/20111018/area-gradient.html

The last line of the following code seems to calculate the maximum value of the Y-axis:

  // Compute the maximum price.
  x.domain([new Date(1999, 0, 1), new Date(2003, 0, 0)]);
  y.domain([0, d3.max(data, function(d) { return d.value; })]);

I'm not happy with the way it gets calculated. I have no knowledge of javascripting at all, but I found out that I could replace the "function(d) { return d.value; })" part by an integer and it would show me a graph which looks better.

I've made a php page which will output the highest value which is in my data set.

My question is now, how can I get the output of the page on the location of this function? It should like this:

y.domain([0, <webpage value>]);

Thanks a lot for your help,

Greggy

Greggy
  • 301
  • 1
  • 4
  • 11

2 Answers2

0

You can check getElementById, depending on how your output looks like.

y.domain([0, getElementById("myPersonalOutput").value]);

Where your page would contain something like

<div id="myPersonalOutput">123456</div>

Mixing PHP and jscript is often times confusing and / or not possible.

Marcel P
  • 101
  • 6
  • Thanks, but I'm not mixing both. The graph is for example in graph.html and the maximum value is displayed in maxval.php. So, somehow I would like to have a solution where javascript would call the maxval.php and output the value which is displayed in the page. – Greggy Dec 16 '16 at 14:00
  • A sample output of maxval.php is for example: 41.464447 – Greggy Dec 16 '16 at 14:01
  • I see, are you able to use jquery on your webpage? With jquery I could see the `$.ajax()` function working for you – Marcel P Dec 16 '16 at 14:10
  • Ok, but how should the coding look like? I found http://stackoverflow.com/questions/18938180/how-to-get-the-html-of-a-div-on-another-page-with-jquery-ajax with some more info. I've added a div with the id 'content' in the php page. In the html page I've change the javascript to y.domain([0, $.ajax({url:maxval.php, type:'GET', success: function(data){$('#content').html($(data).find('#content').html());}});]); ...but doesn't work. – Greggy Dec 16 '16 at 14:42
  • Okay, I think my first idea was not the best one @Greggy – Marcel P Dec 19 '16 at 11:17
  • Another comment, because i could not edit my previous one @Greggy. Another try: an easier way would be using the `$.get()` function. See: [link](http://api.jquery.com/jQuery.getJSON/). This would look like `y.domain([0, $.get("maxval.php", function( data ) { return data; });]);` P.S.: this is not the safest way to transmit data, please be aware of this! – Marcel P Dec 19 '16 at 11:22
  • Hmm, it looks like this one is also not working. When I put it in an alert, it doesn't show me anything. alert($.get("maxval.php", function( data ) { return data; });); – Greggy Dec 20 '16 at 10:00
  • Another try: `var a = $.get("maxval.php", function( data ) { return data; }); alert (a);` This gives me a pop-up with: [object Object], so if I get this correct, it should be converted somehow to a float or double. – Greggy Dec 20 '16 at 10:20
0

I found the solution via jquery ajax get responsetext from http url .

var response = ''; $.ajax({ type: "GET",url: "maxval.php", async: false,success : function(text){response = text;} });
y.domain([0, response]);
Community
  • 1
  • 1
Greggy
  • 301
  • 1
  • 4
  • 11