Sign in to follow this  
cvh

Unnecessary Brackets Interfere With Rendering

Recommended Posts

Hello,

 

I'm using Google GSON to build my JSON content, which I then use in a Scatter chart. The GSON produces valid JSON (which I have verified by running through the validator at jsonlint.com), but the Scatter chart fails to display correctly - the caption, palette, number prefix, axis names etc. don't show.

 

By tinkering with the JSON I find it all works as intended (i.e. all chart elements display correctly) if I remove a few brackets, which are causing the problem - please see the .png attachment to this thread to see what I mean by unnecessary brackets.

 

My question is - how do I get the JSON into a form recognised by FusionCharts, as having valid JSON seems somehow to be insufficient?

 

(I have also attached the HTML generated so the FusionChart moderators can try and reproduce the problem and the fix).

 

Thank you.

post-25683-0-78891600-1330013606_thumb.png

0010010011_2012-02-23_15:37:10.html

Share this post


Link to post
Share on other sites
Guest Sumedh

Greetings, smile.gif

 

GSON service will not provide the valid JSON which is required to a plot chart.

 

You will have to implement your own code, to generate a valid JSON.

 

Hope this helps. smile.gif

Share this post


Link to post
Share on other sites

Thank you for your reply. Does this mean that FusionCharts doesn't adhere to the JSON standard? Or are you saying that GSON doesn't output valid JSON? If the latter then that's surprising, as I have run the JSON generated by GSON through a number of validators and it passes every time.

Share this post


Link to post
Share on other sites

For anyone else stumbling into this issue, I fixed it by this horrible hack (which just feels wrong!):

 

1. generate your JSON using GSON

 

2. strip the offending brackets - I used StringUtils from the lang library of the Apache Commons project - see here.

 

3. The Java code I used was as follows:

 

String generatedJson = StringUtils.replace(generatedJson, "}},{", "},");

 

NB - line 3 above assumes you are generating compact JSON, i.e. not using the 'pretty printing' constructor of GSON. If you use pretty printing you will need to handle the line breaks between the curly braces.

Edited by cvh

Share this post


Link to post
Share on other sites
Guest Sumedh

Hi, smile.gif

 

I am glad that, you have managed to resolve your issue.

 

And also, thanks a lot for the post.tongue.gif

 

Appreciate your efforts.smile.gif

 

Happy FusionCharting ! biggrin.gif

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this