javascript jqPlot 自定义刻度标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9263551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:06:45  来源:igfitidea点击:

jqPlot custom tick labels

javascriptjqplot

提问by HiveHicks

I've got data with X values from 0 to 55. I would like to see these values as a custom text in tick labels. Ideally, I want to specify some callback, like

我有 X 值从 0 到 55 的数据。我希望将这些值视为刻度标签中的自定义文本。理想情况下,我想指定一些回调,比如

function tickLabel(tickValue) {
    return "This is " + tickValue;
}

Is it possible?

是否可以?

回答by HiveHicks

I've found a solution.

我找到了解决办法。

xaxis: {
  tickRenderer: $.jqplot.AxisTickRenderer,
  tickOptions: {
    formatter: function(format, value) { return "This is " + value; } 
  }
}

回答by groovekiller

Use something like:

使用类似的东西:

var line1 = [['This is '.$value, $value], ...]

And call your plot as:

并将您的情节称为:

var plot1 = $.jqplot('chart1', [line1], {
    title: 'Title of your plot',
    series:[{renderer:$.jqplot.BarRenderer}],
    axesDefaults: {
        tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
        tickOptions: {
          angle: -30,
          fontSize: '10pt'
        }
    },
    axes: {
      xaxis: {
        renderer: $.jqplot.CategoryAxisRenderer
      }
    }
  });