javascript - jqplot反转y轴点等问题

标签 javascript jquery jqplot

我得到这样的结果: enter image description here

这很奇怪,因为我到底为什么在 y 轴上得到这个值1 1 2 2 2。我预期的 Y 轴点只是 1 和 2,因为我得到的结果是

[[["2013-01-30", "2"], ["2013-01-31", "2"], ["2013-02-01", "1"]] ]

我在这里想做的是将 Y 轴反转为 1 作为最高或顶部,就像屏幕截图中一样。

这是我的代码:

我通过 ajax 在我的 json 结果中得到这个。这是结果:

[{"execution_datetime":"2013-01-30","sales_rank":"2"},{"execution_datetime":"2013-01-31","sales_rank":"2"} ,{"execution_datetime":"2013-02-01","sales_rank":"1"}] ,即 jQuery.each 上的数据结果

  var response =[[]];
    var maxSR = 1;
    jQuery.each(data, function(index, value) {
        if( this.sales_rank > maxSR ) {
        maxSR = this.sales_rank; //I am getting the largest number in the response array so that I can assign it on the Y-AXIS MIN 
        }
        response[0].push([this.execution_datetime, this.sales_rank]);
    });

    //response has already a value of:
    //[[["2013-01-30", "2"], ["2013-01-31", "2"], ["2013-02-01", "1"]]]

    var tmpMin = response[0][0];
    var xMin = tmpMin[0];

    var plot2 = $.jqplot('myChart',response,{
    axes:{
        xaxis:{
            renderer:$.jqplot.DateAxisRenderer,
            tickOptions:{formatString:'%b %#d'},
            tickInterval:"1 days",
            min: xMin,
          },
        yaxis:{
            tickOptions:{ formatString:'%d'  },
            max:1,
            min:parseInt(maxSR),
        },
    },
        highlighter:{
            show:true,
            sizeAdjust: 7.5,
        },
        cursor: {
          show:false,
        },
  });

我还尝试删除 y 轴上的 tickOptions:{ formatString:'%d' }, ,它似乎有效,问题是,我的屏幕上出现了一些 float 我不喜欢 Y 轴。我该如何解决这个问题?

如果这个问题得到解决,另一个问题是,是否可以设置一种到 x 轴的偏移量,以便这些点不会位于边界上?

我们将非常感谢您的帮助!谢谢你! :)

最佳答案

用这个你可以反转 Y 轴值:

tickOptions:{ formatString:'%i'}

要消除 y 轴 1 1 2 2 2 上的值,您应该使用:

numberTicks: value 

is it possible to set a kind of offset to the x axis so that the points won't lie on the border?

你可以使用这个:

xaxis:{
//
min: xMin <-- subtract 1 to this value.

//
yaxis:{
   min: parseInt(maxSR) <-- subtract 1 to this value.

关于javascript - jqplot反转y轴点等问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14651697/

相关文章:

java - 如何使用 jqplot 仅显示堆积条形图的标签总和?

javascript - 在 Raphael 中通过 CSS 控制矩形的填充

javascript - JS中如何下载多个文件

php - 如何将ajax添加到wordpress主题

javascript - 单击其中的元素时 DIV 失去焦点

javascript - jquery resizable() 不工作(示例)

jqPlot - 如何更改 canvasOverlay 的不透明度或 z-index?

javascript - AngularJS:你能从多个 $scope.$apply() 调用中得到 'digest in progress' 错误吗?

javascript - html5 拖放 e.stopPropagation();

css - 可调整大小的图表