echarts图表多个柱状图不显示,单个能显示

是关于调查问卷的结果分析,设置了flag判断是单选还是多选或填空,是单选则使用if语句执行下面的echarts代码
 

<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
                    <div id="main<%=flag%>" style="width: 500px;height:400px;"></div>

                    <script type="text/javascript" >
                        //var flag1=0;
                        var count1=[];
                        //var count2=["A","B","C","D","E","F","G","H","I","J","K","L","M","N"];
                        var count3=[];

                        <%
                        int len=count.length;
                        %>
                        <%
                        for(int i1=0;i1<len;i1++){
                            if(sel[i1]!=null){
                            %>count1[<%=i1%>]=<%=count[i1]%>;
                            count3[<%=i1%>]=<%=sel[i1]%>;
                        <%}
                        }%>

                        //flag1=count1.length;

                        // 基于准备好的dom,初始化echarts实例
                        var myChart<%=flag%> = echarts.init(document.getElementById('main<%=flag%>'));
                        myChart<%=flag%>.clear();
                        myChart<%=flag%>.resize();
                        // 调用showLoading方法
                        myChart<%=flag%>.showLoading({
                            text: 'loading',
                            color: '#c23531',
                            textColor: '#000',
                            maskColor: 'rgba(255, 255, 255, 0.2)',
                            zlevel: 0,
                        });;
                        setTimeout(() => {
                            // setOption前隐藏loading事件
                            myChart<%=flag%>.hideLoading();
                            myChart<%=flag%>.setOption(Option);
                        }, 1000);
                        var Option={
                            title: {
                                text: '统计结果'
                            },
                            tooltip: {show:true},
                            legend: {
                                data:['选择次数']
                            },
                            xAxis: {
                                data:count3
                            },
                            yAxis: {},
                            series: [{
                                name: '选择次数',
                                type: 'bar',
                                data: count1
                            }]
                        };
                        myChart<%=flag%>.set(Option);
                        
                        myChart<%=flag%>.clear();
                        myChart<%=flag%>.resize();
                        <%
                        flag++;
                        count=null;
                        sel=null;
                        %>
                        count1=null;
                        count3=null;
                        System.gc();
                    </script>

单个问题的分析结果图是能显示的

两个及以上的图表就显示不出来,连加载都没有

同一界面上如果出现了多选题,也不能显示

但是有的两个单选能显示

如果把echarts里的data预先设定好数据,则会出现最后一个能显示,上面的图表全在加载中

 

下面是关于单选多选填空获取答案和百分比的代码,其中单选设置了记录选项内容和选择人数的数组供echarts使用

 if (list.size() > 0) {
                            int flag=0;
                            for (int i = 0; i < list.size(); i++) {

                                int count[]=new int[10];
                                String sel[]=new String[10];
                                int flag2=0;

                                if (list.get(i).getO_content().equals("") || list.get(i).getO_content() == "") {
                    %>
                    <br>
                    <label><%=i + 1%>、<%=list.get(i).getQ_content()%>【填空题】</label>
                    <input type="text" style="display: none;" value="<%=list.get(i).getQ_id()%>" name="tkqid<%=tk%>">

                    <% String[] strings = list.get(i).getAnswers().split("&");
                        for (int j = 1; j < strings.length; j++) {
                    %>
                    <ul>
                        <li style="color: #01AAED"><%=strings[j]%>
                        </li>
                    </ul>
                    <%
                        }
                        tk += 1;
                    } else {
                        String[] strings = list.get(i).getO_content().split("#");
                        if (strings[1].substring(1, 3).equals("多选")) {
                        	flag2=1;
                    %>

                    <br>
                    <label><%=i + 1%>、<%=list.get(i).getQ_content()%> 【多选】</label>
                    <input type="text" style="display: none;" value="<%=list.get(i).getQ_id()%>" name="dxqid<%=mx%>">
                    <%
                        String[] strings1 = list.get(i).getAnswers().split("&");
                        int num = 0;
                        for (int n = 1; n < strings1.length; n++) {
                            num = num + Integer.parseInt(strings1[n]);
                        }
                        for (int j = 1; j < strings.length; j++) {

                            if (j == 1) {
                    %>
                    <br><p style="margin:0.1em 0;">&nbsp;&nbsp;&nbsp;<input type="checkbox" value="<%=strings[j].substring(4)%>"
                               name="mx<%=mx%><%=imx%>"><%=strings[j].substring(4)%> &nbsp; &nbsp;&nbsp;
                    &nbsp;<b style="color: #01AAED"><%=Integer.parseInt(strings1[j]) * 100 / (float) num %>%</b></p>
                   
                    <%
                    } else {
                    %>
                    <p style="margin:0.1em 0;">&nbsp;&nbsp;&nbsp;<input type="checkbox" value="<%=strings[j]%>" name="mx<%=mx%><%=imx%>"><%=strings[j]%>&nbsp;
                        &nbsp;&nbsp; &nbsp;<b style="color: #01AAED"><%=Integer.parseInt(strings1[j]) * 100 / (float) num %>%</b></p>
                    
                    <%

                            }
                            
                            imx += 1;

                        }%>

                <input type="text" style="display: none;" value="<%=imx%>" name="imx<%=mx%>">
                    <%
                            imx = 0;
                            mx += 1;
                        }




                        if (strings[1].substring(1, 3).equals("单选")) {
                        	flag2=2;

                    %>


                    <label><%=i + 1%>、 <%=list.get(i).getQ_content()%>【单选】</label>
                    <input type="text" style="display: none;" value="<%=list.get(i).getQ_id()%>" name="ddxqid<%=dx%>">
                    <%

                        String[] strings2 = list.get(i).getAnswers().split("&");
                        int num2 = 0;
                        for (int n2 = 1; n2 < strings2.length; n2++) {
                            num2 = num2 + Integer.parseInt(strings2[n2]);
                        }
                        for (int n = 1; n < strings.length; n++) {
                            if (n == 1) {
                    %>
                    <p style="margin:0.1em 0;">&nbsp;&nbsp;&nbsp;<input type="radio" value="<%=strings[n].substring(4)%>"
                               name="dx<%=dx%>"><%=strings[n].substring(4)%>&nbsp; &nbsp;&nbsp;
                        &nbsp;<b style="color: #01AAED"><%=Integer.parseInt(strings2[n]) * 100 / (float) num2%>%</b></p>
                    <%
                        sel[n-1]=strings[n].substring(4);
                    //存储选项的数组
                    %>
                    <%
                    } else {
                    %>
                    <p style="margin:0.1em 0;">&nbsp;&nbsp;&nbsp;<input type="radio" value="<%=strings[n]%>" name="dx<%=dx%>"><%=strings[n]%>&nbsp; &nbsp;&nbsp;
                        &nbsp;<b style="color: #01AAED"><%=Integer.parseInt(strings2[n]) * 100 / (float) num2%>%</b></p>
                    <%
                        sel[n-1]=strings[n];
                    //存储选项
                    %>
                    <%
                                            }

                    count[n-1]=Integer.parseInt(strings2[n]);
                    //存储选项被选择的人数
                    //flag++;


                                        }

                                        dx += 1;
                                    }



                                }

跪求大佬解答!

好多特殊符号~,看不下去,我的处理方式是先根据条件判断组合成不同的配置数据,在渲染

如果对您有帮助,请你点赞 + 采纳,这是对我最大的鼓励

option 其实就是一个json 格式的对象,最好按json 对象改变值