我想绘制JPEG的系数直方图。我正在Google上搜索几个小时,以了解如何使用Chart2D库,但没有示例教程。我想绘制的数组是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();
有什么不对?
有没有可以帮助我的例子的任何教程? – muhannad 2012-04-01 14:09:08
我会从[Chart2D教程](http://chart2d.sourceforge.net/Chart2D_1.9.6/Tutorial/Tutorial.htm)开始。 – trashgod 2012-04-01 14:12:37
我看过了,但没有明显的例子!!!! – muhannad 2012-04-01 14:16:38