1

当动态加载图表时,x 轴比例正在增加到 0.2。我想让比例增加 1 (1,2,3,4) 等而不是 0.2 (0.0, 0.2, 0.4, 0.6) 等。

有人可以帮忙吗?

这是我的代码:

 $(document).ready(function(){
              // Some simple loops to build up data arrays.
              var cosPoints = [];
              var j = 0;
              var k = 0;
              for (var i=0; i<2*Math.PI; i+=0.4){ 
                cosPoints.push([i, Math.cos(i)]);
                j = i;
              }

              var sinPoints = []; 
              for (var i=0; i<2*Math.PI; i+=0.4){ 
                 sinPoints.push([i, 2*Math.sin(i-.8)]); 
                 k = i;
              }

              var powPoints1 = []; 
              for (var i=0; i<2*Math.PI; i+=0.4) { 
                  powPoints1.push([i, 2.5 + Math.pow(i/4, 2)]); 
              }

              var powPoints2 = []; 
              for (var i=0; i<2*Math.PI; i+=0.4) { 
                  powPoints2.push([i, -2.5 - Math.pow(i/4, 2)]); 
              } 

              var plot1 = $.jqplot('chart1', [cosPoints, sinPoints], 
                { 
                  title:'Line Style Options', 
                  // Series options are specified as an array of objects, one object
                  // for each series.
                  series:[ 
                      {
                        // Change our line width and use a diamond shaped marker.
                        lineWidth:2, 
                        markerOptions: { style:'dimaond' }
                      }, 
                      {
                        // Don't show a line, just show markers.
                        // Make the markers 7 pixels with an 'x' style
                        showLine:false, 
                        markerOptions: { size: 7, style:"x" }
                      }
                  ]
                }
              );
            //in every 5s interval replot the graph with newData (new random data)          
                var intervalId = setInterval(function() {
                    var newData1 = new Array();
                    var newData2 = new Array();
                    newData1 = cosPoints;
                    newData2 = sinPoints
                    //remove the first element from the data array
                    newData1[0].shift();
                    newData2[0].shift();
                    //add a new element to the end of the array
                    j = j+0.4;
                    k = k+0.4;
                    newData1[0].push([j, Math.cos(j)]);
                    newData2[0].push([k, 2*Math.sin(k-.8)]);
                    plot1.series[0].data = newData1[0];
                    plot1.series[1].data = newData2[0];
                    plot1.resetAxesScale();
                    plot1.replot();
                }, 1000); 
            });
4

1 回答 1

2

对于初始加载,您必须使用以下命令为 x 轴定义 tickInterval:

var plot1 = $.jqplot('chart1', [cosPoints, sinPoints], {
  title : 'Line Style  Options',
  axes: {
   xaxis: { tickInterval: 0.5} //Needed interval between ticks
  },
  series: [...]
});

对于动态加载,您必须在 setInterval 函数中添加这两行(在 plot1.resetAxesScale() 和 plot1.replot() 语句之间):

plot1.axes.xaxis.tickInterval = 0.5;
plot1.axes.xaxis._tickInterval = 0.5;
于 2013-11-12T08:11:01.590 回答