ThymeleafとJFreechartの両方に新しく追加されました。 1つのhtmlページに複数の棒グラフを表示する必要があります。これは私がThymeleafを使用した例を見つけ成し遂げる方法の研究からは、以下のように:ThymeleafテンプレートのJFreeChart棒グラフを表示
JFreeChart chart = createChart(pdSet, "Test Pie Chart using JFreeChart");
try{
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400);
response.getOutputStream().close();
} catch(IOException ex) {
ex.printStackTrace();
}
私がイメージとしてHTMLに埋め込むことができるようにモデルにレンダリングされたチャートを渡すことができるようにする必要があります。私はこれをバイト配列として渡そうとしましたが、成功しませんでした。 コントローラーコード:
JFreeChart chart = ChartFactory.createBarChart(null, null, null, bardataset, PlotOrientation.VERTICAL, false, false, false);
File file = new File("barchart.jpg");
try {
ChartUtilities.saveChartAsJPEG(new File(filename), chart, 800, 100);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (clientList != null){
model.addAttribute("chart", chart);
}
chart.html:
<div>
<p> Bar Graph</p>
<div>
<img th:src="@{~/chart}" width="1000"/>
</div>
</div>
</div>
私が出会った例から、上記の実装... は、MVCのためにそれに関連する依存関係に春ブーツ1.4.3でこれを実行します、Thymeleaf、Security and JPA on Java jdk1.8.0_111。
ご迷惑をおかけして申し訳ございません。