score:1
You don't need to manually create json in your controller code, spring boot will handle it for you. You should create a dto class in a form which is expected by your javascript.
Which is in your case:
public class LineChartDto {
private List<Integer> month; // you better call this "months" or "monthList"
private List<BigDeciamal> report; // why do you call this "report" while this is actually "sales"
// all args constructor, getters
}
And your controller method would be:
@RequestMapping("/linechartdata")
@ResponseBody // or use @RestController
public LineChartDto getSalesLineChartData(..) {
List<Report> reportList = ..
List<Integer> months = reportList.stream()
.map(report -> report.getMonth()+1)
.collect(Collectors.toList());
List<BigDecimal> sales = reportList.stream()
.map(Report::getTotal_sales) // better name this getTotalSales
.collect(Collectors.toList());
return new LineChartDto(months, sales);
}
Response will result in json object:
{
"month": [1, 2, ... ],
"report": [100, 200, ... ]
}
As for why you ajax doesn't work - the question is too broad. Start with Chrome Dev Tools Network to check what network communication is happening, check browser console for errors, add some console.log() or better debug your js.
This line document.addEventListener('DOMContentLoaded', function ()
looks suspicious to me. I don't think you need to addEventListener each time you call your chart.
Probably you should do this:
function drawLineChart(month,report){
Highcharts.chart('container', {
...
Source: stackoverflow.com
Related Query
- Highchart in Spring boot
- Draw pie chart using spring boot, thymeleaf, js, highchart but can't
- Strange character in the Highstock source code
- Why does my Highchart look different when I transfer my code from Jsfiddle to my server?
- I had follow someone code samples and try apply to my HighChart program but I can't get it work at all
- Column based Highchart drilldown series assign color code to each column
- x-axis, y-axis lines does not appear, when I include 3D chart library of HighChart in my code
- why my highchart code is not working?
- How to render Gantt Highchart from data source
- Highchart spline Cut Off when reach to maximum scale value. How can it fixed?. I have attached may sample code on body
- I am trying to include india map in my highchart code
- Highchart map does not support IRS country code
- Highchart columnrange, color code lines based on data
- how to hide highchart x - axis data values
- Highchart specific width stack column bar graph
- Highchart - show / hide an y-Axis without hiding the series
- Manage multiple highchart charts in a single webpage
- when is a highchart completely loaded?
- Remove Export and print button plugin on highchart chart
- Drilldown multiple levels Highchart
- How to display highchart series line marker symbol from tooltip formatter?
- Highchart - change color of one x-axis label only
- Resolve Conflict When Using Highchart and Highmap together (TypeError: ma is not a function)
- use highchart and highstock on the same page
- Highchart series update in javascript
- Can I use two different formatters for highchart tooltips?
- How to change the font family of Highchart to Bootstrap css default font family
- Highchart hide default buttons
- How to export a Highchart chart to PDF thanks to a button outside the chart?
- Displaying Persian dates in highchart from its corresponding Georgian date
More Query from same tag
- Highchart in Spring boot
- How can I add a Bar Chart to my Django based Database?
- resize on load of highcharts in gridster widget
- Clickable HTML element that closes Highcharts tooltip
- 24-Hour Time Event Chart using HighCharts
- Format categories (x-axis) for highcharts
- How are Highcharts event listeners handled
- Adding dynamic irregular data to area chart causes it to shift
- Error in systemjs using angular2-highcharts
- How do I use an Highcharts Solid Gauge in angular 6 with typescript?
- *Highcharts* How to get the min and max value of the zoom box
- Is there a highcharts way to sequence series by serie types?
- Parsing JSON data for Highcharts
- React Highcharts v9.2 Solid Gauge Rounded Ends
- Need to render charts in my view but it returns Undefined variable: chart
- Highcharts fixed / floating axis
- HighCharts Pie chart is not showing all of dataLabels, it's cut off
- Highcharts: How to plot adjacent scatter points for different box plots
- Unable to load json File for highcharts
- Highcharts not rendering data points
- onclick handler in custom exporting button in highcharts-vue fails with 'Cannot read property 'call' of undefined'
- rCharts: Change the individual point colors of a time series plot (Highcharts)
- Highcharts error #15, graph is displayed correctly
- Angular Highcharts list of charts with ng-repeat
- Setting highcharts datalabels backgroundColor with the same color of its serie
- How to add math equations in highcharts?
- How To Change The Color of specific span of data in a chart
- Drag legend out of Highchart
- how to set the interval of points on Y - Axis highcharts
- If Array is Empty PHP - Highcharts