0

I have a candlestick chart to plot with a set of JSON data that are built with Gson, coming from the SPringboot2 api. I am not too sure if the JSON format generated by Gson is not valid and compatible with the JSON parser. It turns out the list of JSON structure is considered to be one array instead of a list of multiple array in the payload. [payload here: https://i.stack.imgur.com/FBNX0.png]

Supposed that the JSON structure should look like as below:

[{"date":"20200505  15:53:00","open":1.089435,"high":1.08967,"low":1.08941,"close":1.08967,"volume":-1},
{"date":"20200505  15:54:00","open":1.08967,"high":1.089845,"low":1.089625,"close":1.08971,"volume":-1},
{"date":"20200505  15:55:00","open":1.08971,"high":1.089755,"low":1.089565,"close":1.089575,"volume":-1},
{"date":"20200505  15:56:00","open":1.089575,"high":1.08958,"low":1.089405,"close":1.08952,"volume":-1},
{"date":"20200506  08:21:00","open":1.083685,"high":1.083745,"low":1.083625,"close":1.083745,"volume":-1}]

The JSONParser in Angular.ts looks like this:

      // Load data
      chart.dataSource.url = "http://localhost:8080/api/candlestick/";
      chart.dataSource.parser = new am4core.JSONParser;
      chart.dataSource.parser.options.emptyAs = 0;

As a result, it's unable to load the chart and generate nothing but blank chart. Is it something to do with the JSON format from Gson output?

cpngjames
  • 35
  • 4
  • Looks like there's an issue with your JSON generation at that endpoint as it's returning your data as a string containing your data. I don't know enough about Spring Boot to point you in the right direction, though. Make sure the content-type is correct (`application/json`) and you're using the proper functionality needed to return your data as JSON instead of a string. – xorspark May 07 '20 at 23:44
  • You are right the end product is serving as a string rather than a JSON. Eventually I have use the JsonArray from Gson instead that works properly. – cpngjames May 08 '20 at 09:01

0 Answers0