清除DIV标记无法正常工作

时间:2013-10-29 17:21:50

标签: javascript css html charts

您好我想使用图表容器在页面中显示两个图表。但我无法清除DIV标签。所以只显示最后一张图表。

<script type="text/javascript">
    $(function () {
        var dataSource =
            [
                { status: "Placed", outsideindia: 6.7, india: 28.6 },
                { status: "Unplaced", unplaced: 9.6 }
            ];

        $("#chartContainer").dxChart({
            dataSource: dataSource,
            commonSeriesSettings: {
                argumentField: "status",
                type: "stackedBar"
            }
        });
    });

</script>



<div id="chartContainer" style="width: 100%; height: 440px;"></div>
<div style="clear: both;"></div>

<script type="text/javascript">
        $(function () {
            $("#chartContainer").dxChart({


                series: {
                    argumentField: "st_status",
                    valueField: "oranges",
                    name: "Series 1",
                    type: "bar",
                    color: "blue"
                }
            });
        });
 </script>

<div id="chartContainer" style="width: 100%; height: 400px;"></div> 请有人帮帮我吗?

2 个答案:

答案 0 :(得分:0)

如果您要清除div的内容,可以使用以下内容:

$('#yourDivID').empty();

答案 1 :(得分:0)

在您的代码中,您在两个div上使用相同的ID。每个元素都应该有唯一的ID。改变并尝试以下:

<script type="text/javascript">
    $(function (){
       var dataSource = [
        { status: "Placed", outsideindia: 6.7, india: 28.6},
        { status: "Unplaced", unplaced: 9.6}
       ];

    $("#chartContainer1").dxChart({
        dataSource: dataSource,
        commonSeriesSettings: {
            argumentField: "status",
            type: "stackedBar"
        },

            </script>


                    <div id="chartContainer1" style="width: 100%; height: 440px;" ></div>
                    <div style="clear:both;"></div>
    <script type="text/javascript">
                $(function ()  
                    {
       $("#chartContainer2").dxChart({


        series: {
            argumentField: "st_status",
            valueField: "oranges",
            name: "Series 1",
            type: "bar",
            color: "blue"
        }
    });
    }

                );
            </script>


    <div id="chartContainer2" style="width: 100%; height: 400px;" ></div>