Java – JfreeChart that uses colourmaps to represent 3D data in 2D graphics
I am currently trying to use JfreeChart to represent 3D data in 2D graphics
Basically, I have a two-dimensional array called data [i] [J] I and j represent the Y and X coordinates I want to plot The value of data [i] [J] represents the frequency value, which I want to represent as color in the figure
I'm not quite sure what such a thing is called, but it looks like this:
Now I've been trying to do this using xyblockrenderer, but I'm having trouble defining a dataset I'm trying to use defaultxyz dataset, but I'm really confused about how to define data here
Can anyone explain how to use defaultxyzdataset to accomplish such a task?
DefaultXYZDataset dataset = new DefaultXYZDataset(); Concentration.dataoutHeight = Concentration.dataout[0].length; System.out.println(Concentration.dataoutHeight); System.out.println(ImageProcessor.MAXCBVINT); double[][] data = new double[3][ImageProcessor.MAXCBVINT]; for (int i = 0; i < Concentration.dataoutHeight; i++) { for (int j = 0; j < ImageProcessor.MAXCBVINT; j++) { data[0][j] = j;//x value data[1][j] = i;//y value data[2][j] = Concentration.dataout[j][i][0];//Colour } dataset.addSeries(i,data); } NumberAxis xAxis = new NumberAxis("Intensity"); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis("Distance to Closest Blood Vessel (um)"); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale scale = new GrayPaintScale(0,10000.0); renderer.setPaintScale(scale); renderer.setBlockHeight(1); renderer.setBlockWidth(1); XYPlot plot = new XYPlot(dataset,xAxis,yAxis,renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); JFreeChart chart = new JFreeChart("Surface Plot",plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); ChartFrame frame = new ChartFrame("Surface Map - " + (Concentration.testing ? "TESTING using " + Concentration.testfile : currentFile.getName()),chart); frame.pack(); frame.setVisible(true);
Solution
You have two options:
>Express them as 3D lib for JfreeChart > you need to use the class: xyblockrenderer, which fully meets your requirements You can download the JfreeChart demo collection, which contains this code (source code of class here) and this complete code example is very similar to 4D