繁体   English   中英

更改x轴的刻度标签

[英]Change the tick label of x axis

我希望在xaxis上显示的刻度线具有y轴的值(仅应更改值,而不应更改位置)。 以下是JsFiddle

https://jsfiddle.net/sonal215/337afs1h/1/

我希望在x轴刻度标签上显示10、5(相应的y轴值),而不是在x轴上显示1、2。

我尝试调试它,库中有一个类jqplot-xaxis-tick设置了ticks值。

<div class="jqplot-axis jqplot-xaxis" style="position: absolute; width: 180px; height: 18px; left: 0px; bottom: 0px;"><div class="jqplot-xaxis-tick" style="position: absolute; left: 47px;">1</div><div class="jqplot-xaxis-tick" style="position: absolute; left: 127px;">2</div></div>

如果我能以任何方式更改在库中显示值的逻辑,那么它将起作用。 还是有其他方法可以做到这一点。

请帮忙

创建jqplot-xaxis-tick div后,您可以对其进行操作,并从s1数据数组为它们分配y值。

$(document).ready(function() {
  var s1 = [
    [1, 10],
    [2, 5]
  ];
  plot1 = $.jqplot('chart1', [s1], {
    seriesColors: ["#EB2300", "#FFCC00"],
    seriesDefaults: {
      renderer: $.jqplot.BarRenderer,
      rendererOptions: {
        varyBarColor: true,
        barWidth: 30,
        barMargin: -30
      },
      pointLabels: {
        show: true
      }
    },
    grid: {
      drawBorder: false
    },
    axes: {
      xaxis: {
        renderer: $.jqplot.CategoryAxisRenderer
      },
      yaxis: {
        tickOptions: {
          show: false
        },
        rendererOptions: {
          drawBaseline: false
        }
      }
    }
  });
 //assign x values with y values//
 $('.jqplot-xaxis-tick').each(function(i,elem) {
        $(this).text(s1[i][1]);
    });
});

在您的小提琴中查看一个有效的示例:

https://jsfiddle.net/337afs1h/2/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM