I want to draw coefficient histogram of JPEG. I'm searching on Google for hours to know how to use Chart2D library, but there is no tutorial with examples. The array which I want to draw is hist[]
. I created an object of LBChart2D
, but I don't know how to set the array as data set to it.
//coeff[] is the coefficients array
for(int i=0;i<coeff.length;i++)
hist[coeff[i]]++;
LBChart2D lbChart2D = new LBChart2D();
EDIT:Here is what I'm trying :
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));
Now It produces an Exception java.lang.NullPointerException
on this line:
BufferedImage lbImage = lbChart2D.getImage();
What's wrong?