3

生成したすべてのJFreeChartを、隅にタイムスタンプを付けて飾りたいと思います。チャートが生成された後に画像を描画する方法はJFreeChartフレームワーク内にありますか?

編集:これらのグラフはバックグラウンドスレッドで生成され、サーブレットを介して配布されているため、GUIはなく、タイムスタンプを別のコンポーネントに表示することはできません。

4

5 に答える 5

4

1 つの方法は、ChartPanel をサブクラス化し、paint(Graphics)メソッドをオーバーライドして最初にチェーンしsuper.paint(Graphics)、続いて追加のテキストをチャートの上にレンダリングすることです。

ただし、これは少しハッキリしているように感じます。個人的には、タイムスタンプを表すa と共にChartPanelを別のコンテナーに追加することをお勧めします。JPanelJLabel

于 2010-11-16T17:16:19.503 に答える
1

addSubtitle()方法はorg.jfree.chart.JFreeChart、適切な代替手段である可能性があります。

于 2010-11-17T15:15:12.600 に答える
1

こちらのフォーラム投稿をご覧ください。

http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=27939

ImageIcon を透かしとして使用します。

ImageIcon icon = new ImageIcon(new URL(watermarkUrl));
Image image = icon.getImage();
chart.setBackgroundImage(image);
chart.setBackgroundImageAlignment(Align.CENTER);
chart.getPlot().setBackgroundAlpha(0.2f);
于 2010-11-16T17:17:31.550 に答える
1

もう少しいじってみたところ、JFreeChart の処理が完了した後に画像に任意に描画できるソリューションを見つけたので、後世のためにここに投稿します。私の場合、チャートを OutputStream に書き込んでいたので、コードは次のようになりました。

BufferedImage chartImage = chart.createBufferedImage(width, height, null);
Graphics2D g = (Graphics2D) chartImage.getGraphics();
/* arbitrary drawing happens here */
EncoderUtil.writeBufferedImage(chartImage, ImageFormat.PNG, outputStream);
于 2010-11-18T18:28:22.610 に答える
0

私の経験では、カスタム情報を JFreeChart に追加する最良の方法は次のとおりです。 - 同じタイプのチャートの BufferedImage をインスタンス化します。- BufferedImage に描画します。- XYImageAnnotation を使用して、現在のプロットに画像を追加します。

これはコードのガイドラインです。

// retrieve image type and create another BufferedImage
int imgType = chart.createBufferedImage(1,1).getType();
BufferedImage bimg = new BufferedImage(width, height, bimg.getType);

// here you can draw inside the image ( relative x & y  )
Graphics2D g2 = (Graphics2D) bimg.getGraphics();
g2.drawString("Hello, JFreeChart " + timestamp, posX, posY );

// instantiate the image annotation, then add to the plot
XYImageAnnotation a = new XYImageAnnotation( x, y, bimg, RectangleAnchor.LEFT );
chart.getPlot().addAnnotation( a );
于 2013-01-28T16:29:23.373 に答える