Does anyone see anything in the following code that would cause the requested information to be returned as junk characters, rather than the intended graph?
The URL seems correct (same URL on the demo instance), but I am not sure I get what garbage characters you are referring to. What you see is the PNG file displayed as a text.
If you want the browser to display the image, you need to tell him that it is an image:
Thanks, Lucas. It is not quite what I am trying to do, but you did remind me of what I need to do. It is part of an AJAX call and needs to to be loaded into the src attribute of an tag.
By the way, what is the best format for the cURL call to the Matomo reporting API when using AJAX to fill the src attribute of an img tag?
As mentioned above you need a Content-Type header. When I add it at the beginning of your PHP I can access the image in the browser.
At your intimation I added the content-type to the AJAX statement as follows:
contentType: ‘image/png’,
Apparently you missed it.
What do you need the AJAX request for? Wouldn’t this do the same?
Yes, it does achieve the embedded graph, but then I would have to create a new file for each and every graph that I wish to display.
My eventual goal is to allow visitors some flexibility in what they see, and for this I need AJAX calls to send their requests to the PHP file that generates their response.