2013-03-06 48 views
5

jqplotを初めて使用しました。棒グラフを描画するときに、x軸は日付、間隔は1日です。jqplotのバー幅が大きすぎる

 axesDefaults:{                 
      tickRenderer: $.jqplot.CanvasAxisTickRenderer,        
     tickOptions:{ 
      fontSize:'10pt', 
     },                   
    },                    
    axes:{                   
     xaxis:{ 
      renderer:$x_renderer,             
      tickOptions:{ 
       formatString:'%Y-%#m-%#d',           
      }, 
      rendererOptions:{              
       tickOptions:{ 
        angle:-90,              
       }                 
       },                  
      label:'$label', 
      tickInterval:'86400000', 
     }, 
     yaxis:{                  
      tickOptions:{ 
       formatString:'%.2f',             
      },                  
      autoscale:true               
     }, 
    },                    
    highlighter:{ 
     show:true,                 
    }, 

しかし、私は、各バーの幅がお互いをカバーするには大きすぎる見つける:これは私のコードの一部です。それを修正するには?

ありがとうございます!

答えて

9

AnthonyLeGovic答えは確かに正しいですが、あなたは次の操作を行うことができ、データポイントの数に応じて、列幅を変更する必要がある場合:

// Get the size of the container of the plot 
var width = jQuery(containerName).width(); 

// Divide by the number of data points. 
width = width/number_of_data_points; 

// Reduce the width to a % of the total for each data point. 
width = (width * 20)/100; 

// Set the value 
$.jqplot(containerName, [data], 
{ 
    // whatever 
    // ... 

    seriesDefault: 
    { 
     renderer: $.jqplot.BarRenderer, 
     rendererOptions: { barWidth: width } 
    } 

    // whatever 
    // ... 
} 

私は凡例の幅を考慮していないことに注意してください。凡例幅はプロット後のみ取得できるので、凡例幅を考慮して列幅を縮小する場合は、プロット後に行う必要があります。

例を示すfiddleを用意しました。

希望します。

10

あなたはシリーズのオプションでそれを指定することができます。

seriesDefault:{ 
    renderer: $.jqplot.BarRenderer, 
    rendererOptions: { 
     barWidth: 5 
    } 
} 

はbarRendererプラグインを含めることを忘れないでください。 jqplot上の棒グラフの詳細ドキュメンテーションについては を見てみてください。Jqplot documentation

+0

感謝。できます。しかし、データポイントの数が増えると、幅がまだ適切であるかどうかはわかりません。私はバーの幅を動的に計算しますが、より良い表示のためにグラフを調整するためのより良い方法がある場合は、 – dusiliang

2

私は以下のコードを追加して結果を得ました。 バー幅がシリーズのデフォルトブロックに設定されていないため、幅の後ろの理由が大きくなりすぎました。

seriesDefault:{ 
    renderer: $.jqplot.BarRenderer, 
    rendererOptions: { 
      barWidth: 5 
    } 
} 

おかげ:あなたの答えのためのAnthonyLeGovic

関連する問題