简体   繁体   中英

Change the tick label of x axis

I want the ticks displayed on xaxis to have value of y-axis(only value should be changed, and not the position). Below is the JsFiddle

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

Rather than 1, 2 being shown on the x axis, i want 10, 5(respective yaxis values) to be shown on the x axis tick label.

I tried debugging it, there is a class jqplot-xaxis-tick in the library which sets the ticks value.

<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>

If i can any way change the logic of displaying the values in the library, then it will work. Or is there any other way to do it.

Please help

You can manipulate the jqplot-xaxis-tick divs after they are created, and assign them the y values from your s1 data array.

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

See a working example in your fiddle:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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