ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Streaming svg
Posted by Adrian on Apr-22-2016 10:26
Hi,

I'm using CD version 6 and Java version 7. This is my question.

Currently in my html page I call a chart by doing the code below. (I'm only showing what's necessary and this all works fine).


// html
<img src="/getChart.do" id="imgID" />


// servlet
WebChartViewer.streamChart(response, xyChart.makeChart2(Chart.PNG));


But I would like to change the code to allow svg instead of PNG.  From the servlet side I know what I need to do, just use Chart.SVG instead of Chart.PNG and set contentTyp/Header accordingly. But what do I put in the html side since I can't use "<img src=>"?  What do you recommend ? Any ideas would be appreciated.

Also, is this the correct way of removing the "<xml> and <!DOCTYPE>" from SVG?
xyChart.setOutputOptions("noxmldecl;dodoctype") ?


Thanks

  Re: Streaming svg
Posted by Peter Kwan on Apr-22-2016 17:53
Hi Adrian,

I think you can just change Chart.PNG to Chart.SVG. Assuming you have a browser that can support SVG properly (like Chrome, FireFox, Safari, IE 9 or above or Edge), the browser should support using SVG as an <IMG> src. The WebChartViewer.streamChart should automatically detect the content type and set the HTTP header automatically, so your code should not need to modify the content type of the header.

If the SVG is intended for the <IMG> tag, you should not remove the <xml> and <!DOCTYPE> header. The WebChartViewer.streamChart relies on these headers to detect if the content is SVG and set the content type header. Also, we have only tested that the browsers <IMG> works with these headers. We have not tested what would happen to the <IMG> tag if the headers are removed.

If you really want to remove the headers, you can use "noxmldecl;nodoctype". (Note: it is nodoctype, not dodoctype as in your message.)

Another thing to note is that the SVG generated by ChartDirector does not have a definite size, as it should be scalable and can assume any size. In HTML, the browser can freely determine its size. If you need to have definite size, you can include the size in the image tag, like <IMG SRC="..." width="400px" /> or use setOutputOptions to include the width and height attributes in the SVG output.

Regards
Peter Kwan

  Re: Streaming svg
Posted by Adrian on Apr-22-2016 21:41
Thank you so much.  I'll give it a try and thanks for the rest of the tips.