2012-04-01 10 views
1

JPEGの係数ヒストグラムを描きたい。 Chart2Dライブラリを使用する方法を数時間Googleで検索していますが、例を含むチュートリアルはありません。描画したい配列はhist[]です。私はLBChart2Dのオブジェクトを作成しましたが、データセットとして配列を設定する方法はわかりません。ヒストグラム(Chart2Dを使用)

//coeff[] is the coefficients array 
for(int i=0;i<coeff.length;i++) 
hist[coeff[i]]++; 

LBChart2D lbChart2D = new LBChart2D(); 

編集:ここでは私がしようとしているものです:

Object2DProperties object2DProps = new Object2DProperties(); 
object2DProps.setObjectTitleText ("Title "); 
Chart2DProperties chart2DProps = new Chart2DProperties(); 
chart2DProps.setChartBetweenChartAndLegendGapThicknessModel(5); 
LegendProperties legendProps = new LegendProperties(); 
legendProps .setLegendBorderThicknessModel(5); 
legendProps.setLegendBackgroundColor(Color.yellow); 
legendProps.setLegendExistence (false); 
GraphChart2DProperties graph2DProps = new GraphChart2DProperties(); 
GraphProperties graphProps = new GraphProperties(); 
object2DProps .setObjectTitleFontName("test"); 
Dataset dataset = new Dataset (1, hist.length, 1); 
for(int i=0;i<hist.length;i++) 
dataset.set (0, i, 0, hist[i]) ; 
LBChart2D lbChart2D = new LBChart2D(); 
lbChart2D.setObject2DProperties (object2DProps); 
lbChart2D.setChart2DProperties (chart2DProps); 
lbChart2D.setLegendProperties (legendProps); 
lbChart2D.setGraphChart2DProperties (graph2DProps); 
lbChart2D.addGraphProperties (graphProps); 
lbChart2D.addDataset (dataset); 
lbChart2D.setSize(width, height); 
BufferedImage lbImage = lbChart2D.getImage(); 
jLabel15.setIcon(new ImageIcon(lbImage)); 

今、それは、この行に例外java.lang.NullPointerExceptionを生成します。

BufferedImage lbImage = lbChart2D.getImage(); 

間違っているのですか?

答えて

2

複数のChart2Ddemosが配布に含まれています。 ImageIOで取得したBufferedImageからデータを収集することができます。 も参照してください。

補足:完全な例がない場合は、validate()を使用してデバッグメッセージを取得できます。少なくともhist.lengthラベルを使用してsetLabelsAxisLabelsTexts()を呼び出していることを確認してください。

//Optional validation: Prints debug messages if invalid only. 
if (!chart2D.validate(false)) { 
    chart2D.validate(true); 
} 
+0

私に役立つ例があるチュートリアルはありますか? – muhannad

+0

私は[The Chart2D Tutorial](http://chart2d.sourceforge.net/Chart2D_1.9.6/Tutorial/Tutorial.htm)から始めたいと思います。 – trashgod

+0

私はそれを読んだが、明白な例は提供されていない!!!! – muhannad

1

ありがとうございました。私はそれを持っていることを心配しないでください。 私はライブラリを使ってヒストグラムを描きました。ここでは私が使ったコードです。

int hist[]=new int[11]; 
int val[]=new int[11]; 
for(int ii=0;ii<11;ii++) 
    hist[ii]=ii-5;//to get negative indeces I used an array to save them 
for(int kk=0;kk<coeff.length;kk++) 
if(coeff[kk]<=5 &coeff[kk]>=-5) val[coeff[kk]+5]++; 
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 
for(int ii=0;ii<hist.length;ii++) 
dataset.setValue(val[ii], "Coefficient value",""+hist[ii]); 
JFreeChart chart = ChartFactory.createBarChart("Original Histogram", 
    "Coefficient value", "", dataset, 
    PlotOrientation.VERTICAL, false,true, false);  
//chart.setBackgroundPaint(Color.yellow); 
chart.getTitle().setPaint(Color.blue); 
CategoryPlot p = chart.getCategoryPlot(); 
p.setOutlinePaint(Color.BLUE); 
p.setRangeGridlinePaint(Color.blue); 
orgim=chart.createBufferedImage(400,400); 
Image im1= orgim.getScaledInstance(jLabel12.getWidth(),jLabel12.getHeight(),1); 
jLabel12.setIcon(new ImageIcon(im1)); 
/// 
+0

です。 – trashgod

関連する問題