如何在jqplot图上改变x轴比例?

时间:2021-12-24 19:36:09

When dynamically loading chart x axis scale is being incremented to 0.2. I would like to have the scale incremented by 1 (1,2,3,4) etc instead of 0.2 (0.0, 0.2, 0.4, 0.6) etc.

当动态加载图表时,x轴比例增加到0.2。我希望刻度增加1(1、2、3、4),而不是0.2(0.0、0.2、0.4、0.6)等等。

Could anyone please help?

有人能帮忙吗?

this is my code:

这是我的代码:

 $(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); 
            });

1 个解决方案

#1


2  

For initial load, you have to define tickInterval for x-axis using :

对于初始负载,必须使用以下方法定义x轴的tickInterval:

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

For dynamic loading, you have to add these two lines in setInterval function (between plot1.resetAxesScale() and plot1.replot() statements) :

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

plot1.axes.xaxis.tickInterval = 0.5;
plot1.axes.xaxis._tickInterval = 0.5;

#1


2  

For initial load, you have to define tickInterval for x-axis using :

对于初始负载,必须使用以下方法定义x轴的tickInterval:

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

For dynamic loading, you have to add these two lines in setInterval function (between plot1.resetAxesScale() and plot1.replot() statements) :

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

plot1.axes.xaxis.tickInterval = 0.5;
plot1.axes.xaxis._tickInterval = 0.5;