highchart图表显示问题

发布于 2021-11-20 02:32:01 字数 20843 浏览 724 评论 0

highchart写了个图表

页面刚进入时不显示图表的数据 横纵坐标都没有

F12按一下就能把数据什么的都刷出来了 其他任何操作都没有

无法截图靠

代码如下:

 //列数据
                        var chartData = new Array();
                        //列名
                        var chartCol = new Array();
                        //年份
                        var chartYear = new Array();
                        //异步获取数据
                        function getChartData(){
                            $.ajax({
                                type: "POST",
                                url: "${ctx}/rawDataChart.do",
                                dataType: 'json',
                                async: false,
                                data: "id=Material_synthesize",
                                success: function(data){
                                    //将后台数据封装到数组中
                                    var text = $.parseJSON(data.toString());
                                    //数组第一位是列名
                                    chartCol = text[0];
                                    //从数组第2个元素开始是数据
                                    for (var i = 1; i < text.length; i++) {
                                        //获得一组数据此时第一个数据时年份
                                        var map = text[i];
                                        chartYear.push(parseFloat(map[0]));
                                        //从第2个开始是真实数据
                                        var dataArr = [];
                                        for (var j = 1; j < map.length; j++) {
                                            dataArr.push(parseFloat(map[j]))
                                        }
                                        //将每组数据添加上
                                        chartData.push(dataArr);
                                    }
                                }
                            }, 'json');
                        }
                        
                        //绘制图表方法
                        function drawChart(){
                            $('#container').highcharts({
                                chart: {
                                    type: 'column',
                                    height: 500,
                                    width: 2000
                                },
                                //标题
                                title: {
                                    text: 'Monthly Average Rainfall'
                                },
                                //副标题
                                subtitle: {
                                    text: 'Source: WorldClimate.com'
                                },
                                //横坐标
                                xAxis: {
                                    categories: chartCol,
                                    labels: {
                                        align: 'right',
                                        rotation: 315,
                                        style: {
                                            color: 'black'
                                        }
                                    }
                                },
                                //纵坐标
                                yAxis: {
                                    min: 0,
                                    title: {
                                        text: '产值/可比价'
                                    }
                                },
                                //提示
                                tooltip: {},
                                plotOptions: {
                                    column: {
                                        pointPadding: 0.2,
                                        borderWidth: 0
                                    }
                                },
                                //数据
                                series: []
                            });
                            //将数据添加到图表
                            var chart = $('#container').highcharts();
                            // 初始化设置chart的series源
                            for (var i = chartData.length - 1; i > -1; i--) {
                                chart.addSeries({
                                    id: i,
                                    name: chartYear[i] + '年',
                                    data: chartData[i]
                                }, false);
                            }
                            //chart.redraw();
                        }
                        $(document).ready($(function(){
                            //初始化获得图表数据
                            getChartData();
                            // 绘制统计图
                            drawChart();
                        }));

求解释求解决办法(PS:MD原来一直是好的用了美工的页面以后成这样了..也不会CSS这事也没法问美工的问题)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文