【问题标题】:how can i paint a graphic in spring mvc in jsp using highchart我如何使用highchart在jsp中的spring mvc中绘制图形
【发布时间】:2019-09-12 17:23:40
【问题描述】:

我想在jsp unsando spring mvc和highchart中画一个图形,但是还是做不到, 我等你的答复谢谢你

我的观点,这是我想绘制图表的地方,但图表没有显示,它什么也没显示

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Chart</title> 
            <script src="resources/assets/js/highcharts.js"></script>
            <script src="resources/assets/js/highcharts-3d.js"></script>
<!--          <script src="resources/assets/js/jquery.js"></script> -->
            <script src="https://code.jquery.com/jquery-3.2.1.js"></script>

    </head>

    <body class="page-container-bg-solid">
        <div class="page-container">
            <div class="page-content-wrapper">
                <div class="page-head" style="background-color:#eff3f8;padding-top:40px">
                    <div class="container">
                        <div class="row" style="margin-bottom:30px">
                            <div class="col-md-6">
                                <h1>my Chart</h1>
                            </div> 
                        </div>
                        <div class="row" style="margin-bottom:30px">                         
                            <div class="col-md-6" style="margin-top:20px">
                                <div id="mychart" style="width:100%; height:400px;"></div>
                            </div> 
                        </div>                        
                    </div> 
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $(function () { 
                Highcharts.setOptions({
                    global: {
                        useUTC: false
                    }
                });
                drawSalesByTypeChart();
                drawSalesByRegionChart();
            });


            function drawSalesByRegionChart() {
                var salesByRegionChart = Highcharts.chart('mychart', {
                    chart: {
                        type: 'pie',
                        margin: 40,
                        options3d: {
                            enabled: true,
                            alpha: 45,
                            beta: 0
                        }
                    },
                    title: {
                        text: 'Sales by Region'
                    },
                    plotOptions: { 
                        pie: {
                            allowPointSelect: true,
                            depth: 35
                        }
                    },
                    series: [{ 
                        name: 'Regions',
                        colorByPoint:true,
                        data: [{
                            name: 'Northeast',
                            y: [[${listGraph}]]
                        }                      
                        ]
                    }]
                });
            }
        </script>        
    </body>
</html>

我的控制器

@RequestMapping(value = "/graphReport")
    public String combo(QcReport qc, Model model) throws IOException {
        List<QcReport> listGraph = assayServ.listGraphAssay();
        model.addAttribute("listGraph", listGraph);
        return ("graphReport");
    }

【问题讨论】:

    标签: java html spring hibernate jsp


    【解决方案1】:

    当我在下面的教程中比较你的工作时:

    https://careydevelopment.us/2017/07/01/add-charts-spring-boot-app-highchart/

    您在传递列表 ${listGraph} 时尝试绘制需要整数值的饼图。

                        series: [{ 
                            name: 'Regions',
                            colorByPoint:true,
                            data: [{
                                name: 'Northeast',
                                y: [[${listGraph}]]
                            }                      
                            ]
    

    【讨论】:

    • 我想显示一个列表而不是整数,我该如何更改它?
    • 因为这是一个列表,所以需要循环遍历元素。 QcReport的类结构是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 2021-12-09
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2017-09-24
    相关资源
    最近更新 更多