今日、新しい PrimeFaces リリース 3.4.RC1 を試してみました。グラフには、datatipFormat という新しい属性があります。
折れ線グラフの値 (y 軸) のみをデータヒントとして表示したい。このような:
<p:lineChart value="#{...}" datatipFormat="y-value"/>
これだけ見せるにはどうしたらいいですか?テンプレート文字列の例が見つかりませんでした。
宜しくお願いします
今日、新しい PrimeFaces リリース 3.4.RC1 を試してみました。グラフには、datatipFormat という新しい属性があります。
折れ線グラフの値 (y 軸) のみをデータヒントとして表示したい。このような:
<p:lineChart value="#{...}" datatipFormat="y-value"/>
これだけ見せるにはどうしたらいいですか?テンプレート文字列の例が見つかりませんでした。
宜しくお願いします
Primefacesは、チャートにjqPlotライブラリを使用します。そこで、次のエントリを見つけました。
私が試したHighlighter.formatString
(Primefaces Showcaseの例):
<p:lineChart id="basic" value="#{userBean.categoryModel}" legendPosition="ne"
datatipFormat="#{userBean.datatipFormat}" title="Basic Bar Chart" min="0"
max="200" style="height:300px"/>
UserBean
public String getDatatipFormat(){
return "<span style=\"display:none;\">%s</span><span>%s</span>";
}
このちょっとしたコツは、y軸の表示だけです。
extender
すべての PrimeFaces チャート タグのプロパティを使用して、デフォルトのプロット オプションをオーバーライドできます。例:
<script type="text/javascript">
function customExtender() {
this.cfg.highlighter = {
useAxesFormatters: false,
tooltipAxes: 'y'
}
}
</script>
...
<p:lineChart extender="customExtender" value="..." />
他の利用可能な jqplot オプションはhttp://www.jqplot.com/docs/files/jqPlotOptions-txt.htmlにありますが、ドキュメントには古いと書かれていることに注意してください。
datatipFormat は sprintf を使用してツールチップの文字列をフォーマットするため、2 番目のパラメーター (y 軸) のみを出力できます。
<p:lineChart value="#{...}" datatipFormat="%2$d"/>
BarChartModel() のヒント:
public String getDatatipFormatX() {
return "<font size=4 color=blue><span style=\"display:none;\">%s</span><span>%s</span></font>";
}
HorizontalBarChartModel() のヒント:
public String getDatatipFormatY() {
return "<font size=4 color=blue><span>%s</span><span style=\"display:none;\">%s</span></font>";
}
使用例:
private void MyCharts(){
//get data (from database, for example) to be displayed
myBarChartModel = new BarChartModel();
myHorizontalBarChartModel = new HorizontalBarChartModel();
ChartSeries verticalSeries = new ChartSeries("verticalSeries");
ChartSeries horizontalSeries = new ChartSeries("horizontalSeries");
myBarChartModel.addSeries(verticalSeries);
myHorizontalBarChartModel.addSeries(horizontalSeries);
myBarChartModel.setDatatipFormat(getDatatipFormatX());
myHorizontalBarChartModel.setDatatipFormat(getDatatipFormatY());
//other chart settings...
}
次に、JSFページで:
<p:chart type="bar" model="#{chartBean.myBarChartModel}" />
<p:chart type="bar" model="#{chartBean.myHorizontalBarChartModel}" />