2012-02-13 9 views
6

X値が0〜55のデータがあります。これらの値はティックラベルのカスタムテキストとして表示したいと思います。理想的には、jqPlotカスタムティックラベル

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

などのコールバックを指定したいと考えていますか?

答えて

17

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

これは最良の汎用的な答えのようですが、私は知っておくべき2つのコーナーケースを発見しました。(1)DateAxisRendererで動作しない可能性があります。 (2)複数のプロットのページに1つのプロットのコンテキストに固有のラベルを出力する必要がある場合、フォーマッタはこのコンテキストを持たない。これらの非標準のケースでは、必要なものに応じて、jQuery.jqplot.DateTickFormatterまたはjQuery.jqplot.CanvasAxisTickRenderer.prototype.draw(置換または呼び出しの折り返しを介して)を行うことをお勧めします。 – sdupton

2

使用のようなもの:

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

として、あなたのプロットを呼び出す:私は解決策を見つけた

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