1
d3.tsv("//localhost/wordpress/" + my_var + ".tsv", function(d) {
d.frequency = +d.frequency;
return d;
}, function(error, data) {
if (error) throw error;

x.domain(data.map(function(d) { return d.letter; }));
y.domain([0, d3.max(data, function(d) { return d.frequency; })]);

I am trying to integrate the my_var variable successfully in the file path but it is not working. Can someone explain me why?

var my_var = <?php echo json_encode($title); ?>;

2 Answers 2

3

This

var my_var = <?php echo json_encode($title); ?>;

evaluates to:

var my_var = sometitle;

and sometitle is probably not defined. You want it to be a string:

var my_var = "<?php echo json_encode($title); ?>";
Sign up to request clarification or add additional context in comments.

Comments

0

That is because my_var is not being treated as a placeholder for a string. Instead, my_var is being treated as a place holder for another variable named <?php echo json_encode($title); ?>. Make the following change and everything should work:

var my_var = "<?php echo json_encode($title); ?>";

var url = "//localhost/wordpress/"
url += my_var
url += ".tsv"

d3.tsv( url, function(d) {
d.frequency = +d.frequency;
return d;
}, function(error, data) {
if (error) throw error;

x.domain(data.map(function(d) { return d.letter; }));
y.domain([0, d3.max(data, function(d) { return d.frequency; })]);

1 Comment

Let me know if you have any concern

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.