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 Articles
- 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
- How to detect the correct date format in highcharts
- How to create a multi y-axis chart with drill down in Highcharts
- EmberJS 2.7 passing data down into a component is failing
- Highchart - give to series-marker other zIndex then to the series-lines
- highstock dual axis tooltip placement
- Y axis does not disappear after setting extremes
- Vue 3 how to correctly update data in Highcharts?
- Apply a linear gradient to a spline with HighCharts
- I want to create a Weibull probability Plot in Angular
- How to create navigation column chart in stacked column high chart
- Is there any replacement of "zones" in highcharts?
- Highcharts capture selection
- Highcharts multiple pie chart series hover
- Add mouseover to outliers but not other points?
- Keep selection in highcharts even on page refresh
- Adding a legend to a pie chart using highcharter, or Rcharts
- How to adjust transparency of inactive series in highcharter with R
- Highcharts: How to change colors of all areas except hovered one on MouseOver event in area plot
- Highcharts: How we can sort series with animation?
- How to add the attribute `preserveAspectRatio` to Highchart svg