0

我正在使用 jqplot 和 dateAxisRenderer 在 x 轴上显示带有日期标签的折线图。但是,我需要使用新数据定期更新该图。调用 replot 时,绘图不会改变,如下例所示。有什么建议么?

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
         <script type="text/javascript" src="../jquery/ui/1.9.2/custom/js/jquery-1.8.3.js"></script>

        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/jquery.jqplot.js"></script> 
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.dateAxisRenderer.js"></script>
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.canvasTextRenderer.js"></script>
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.canvasAxisTickRenderer.js"></script>
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.AxisLabelRenderer.js"></script>
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.categoryAxisRenderer.js"></script>
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.barRenderer.js"></script>
        <script type="text/javascript" src="../jquery/plugins/jqplot/dist/plugins/jqplot.enhancedLegendRenderer.js"></script>

        <link rel="stylesheet" type="text/css" href="../jquery/plugins/jqplot/dist/jquery.jqplot.css" />
    </head>

    <body>
        <div id="chartdiv" style="height:400px;width:800px;"></div>

        <script type="text/javascript">
            $(document).ready(function(){
                var line1 = [
                    [new $.jsDate("2013-01-28 1:10PM"), 1.0],
                    [new $.jsDate("2013-01-28 1:11PM"), 2.0],
                    [new $.jsDate("2013-01-28 1:12PM"), 4.0],
                    [new $.jsDate("2013-01-28 1:13PM"), 8.0],
                    [new $.jsDate("2013-01-28 1:14PM"), 16.0],
                    [new $.jsDate("2013-01-28 1:15PM"), 32.0]
                ];
                var plot2 = $.jqplot('chartdiv', [line1] ,{
                    series:[{lineWidth:4, showMarker:false, renderer:$.jqplot.LineRenderer}],
                    axesDefaults: {
                        tickRenderer: $.jqplot.CanvasAxisTickRenderer
                    },
                    axes:{
                        xaxis:{
                            renderer:$.jqplot.CategoryAxisRenderer,
                                tickOptions:{
                                    formatString:'%F %X',
                                    angle: -30
                                }
                        },
                    }
                });

                alert("wait");
                line1 = [
                    [new $.jsDate("2013-01-28 1:10PM"), 32.0],
                    [new $.jsDate("2013-01-28 1:11PM"), 16.0],
                    [new $.jsDate("2013-01-28 1:12PM"), 8.0],
                    [new $.jsDate("2013-01-28 1:13PM"), 4.0],
                    [new $.jsDate("2013-01-28 1:14PM"), 2.0],
                    [new $.jsDate("2013-01-28 1:15PM"), 1.0]
                ];
                plot2.data = [line1];
                plot2.replot({resetAxes:true});
            });
        </script>
    </body>
</html>
4

1 回答 1

1

我最近对 ​​jqplot 做了一些工作,发现数据处理中的不一致有点令人沮丧。

给定您的示例plot2:对于条形图,您必须先看一下然后plot2.series[i].data再看它(参考:http ://www.jqplot.com/deploy/dist/examples/selectorSyntax.html )plot2.datareplot()

例如对于您的代码

            ...
            plot2.series[0].data = [line1];
            plot2.replot({resetAxes:true});
            ...

我试图抽象出不同图表类型的细微差别,但在此之前,我一直在通过将其存储data在父对象上、破坏绘图然后使用$.jqplot(e, data,options)

于 2013-01-28T11:11:14.453 回答