0

csv ファイルから取得したデータを作成しましたhighchart。グラフは正常に機能し、正常にプロットされています。しかし、問題は、ページが更新されたときに csv ファイルから最新の値が取得されないことです。古いグラフが表示されたままです。ブラウザーを閉じて、チャートを再度開くと正常に動作します。 csv から更新された値でリセット/再描画する方法を教えてください。以下は私のコードです。この問題は、Firefox ではなく IE で発生しています。表示されたグラフを右クリックして Excel にエクスポートすると、更新された値が表示されますが、更新された値でグラフが描画されません。

  <html> 
  <head>

  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <meta http-equiv="Cache-Control" content="no-store" /> 
   <LINK  REL="StyleSheet" HREF="../style/default.css" TYPE="text/css"
 MEDIA="screen">        
  <script type="text/javascript" src="../js/jquery.min.js"></script>        
  <script type="text/javascript"  src="../js/highcharts.js"></script>

    <script type="text/javascript">
    var chart;
    $(document).ready(function() {      
                 cache:false
                 var options="";
         options = {
            chart: {
                renderTo: 'container',
                defaultSeriesType: 'column'
            },
            title: {
                text: 'Incident Status'
            },
            xAxis: {
                categories: []
            },
            yAxis:

            {
             allowDecimals:false, tickInterval:15,
                title: {
                    text: 'Issue Count'
                }
            },
            series: []          
          };

        /*
         Load the data from the CSV file. This is the contents of the file:

            Apples,Pears,Oranges,Bananas,Plums
            John,8,4,6,5
            Jane,3,4,2,3
            Joe,86,76,79,77
            Janet,3,16,13,15

         */             $.get('../data/incident_status.txt', function(data) {
            // Split the lines
            var lines = data.split(';');
            $.each(lines, function(lineNo, line) {
                var items = line.split(',');

                // header line containes categories
                if (lineNo == 0) {
                    $.each(items, function(itemNo, item) {
                        if (itemNo > 0) options.xAxis.categories.push(item);
                    });
                }

                // the rest of the lines contain data with their name in the first position
                else {
                    var series;

                    series= {
                        data: [],
                        pointWidth: 28

                    };
                    $.each(items, function(itemNo, item) {
                        if (itemNo == 0) {
                            series.name = item;
                        } else {

                            series.data.push(parseFloat(item)); 

                        }
                    });
                options.series.push(series);
                }
            });

            chart = new Highcharts.Chart(options);
            chart.destroy();

                        chart = new Highcharts.Chart(options);          
       });


    });         </script>

    <body>
                        <div id="wrapper">
                            <div  class="container">

                        <div id="banner" >
                            <div class="img-border"> <img src="../images/logo.jpg" width="1120" height="111px" alt="" /> </div>
                        </div>

                        <div id="container" style="width: 100%; height: 400px; margin: 0 auto"></div>

                        <?php include('../control/incidentstatus_gen.php');?>

                            </div>

                        </div>



<body> </html>
4

1 に答える 1

1

$.gt がブラウザのキャッシュからファイルを取得しているようです。これを回避する方法は、変数パラメーターを追加することによってリクエストを一意にすることです。Jqueryがお手伝いします

$.ajaxSetup({
    // Disable caching of AJAX responses
    cache: false
});

または、日時パラメーターを追加してリクエストを一意にすることで、自分で行うこともできます。

$.get(filename,{ "_": $.now() }, function(data){
    ...
});
于 2013-03-25T07:03:09.647 に答える