Trying to set the block height and width in XYBlockRenderer
Trying to set the block height and width in XYBlockRenderer
Hi
I am trying to set the block height and width in XYBlockRenderer to 10. My chart has 100 data items to be shown but only one data item gets drawn with 10X10 dimensions. Others still take 1X1. Why is it such? If of any help, the last data item takes the correct size but others still have 1 axis unit for both height and width.
I am trying to set the block height and width in XYBlockRenderer to 10. My chart has 100 data items to be shown but only one data item gets drawn with 10X10 dimensions. Others still take 1X1. Why is it such? If of any help, the last data item takes the correct size but others still have 1 axis unit for both height and width.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Trying to set the block height and width in XYBlockRende
Can you show some code?
Re: Trying to set the block height and width in XYBlockRende
I am just setting the block height and width using this:
I am drawing 6 cells and output comes like thishttps://drive.google.com/open?id=0Bwt0u ... i1jZ0FBRGM.
Code: Select all
renderer.setBlockHeight(10);
renderer.setBlockWidth(10);
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Trying to set the block height and width in XYBlockRende
With "code", I actually meant an SSCCE including the data values.
But at least, the image is helpful. It seems that your data items simply overlap.
But at least, the image is helpful. It seems that your data items simply overlap.
Re: Trying to set the block height and width in XYBlockRende
In this piece of code, can you please tell how are my items overlapping:
Code: Select all
public class Demo3 {
static double[] xvalues = new double[10 * 10];
static double[] yvalues = new double[10 * 10];
static double[] zvalues = new double[10 * 10];
static double[][] data = new double[][] { xvalues, yvalues, zvalues };
static XYBlockRenderer renderer;
public static void blockRenderer(String title) {
JFrame f = new JFrame();
// f.setLayout(new GridLayout());
ChartPanel chartPanel = createDemoPanel();
// chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
f.add(chartPanel);
System.out.println("Renderer height and width "
+ renderer.getBlockHeight() + " " + renderer.getBlockWidth());
f.setSize(new java.awt.Dimension(700, 500));
f.setVisible(true);
f.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
}
private static JFreeChart createChart(XYZDataset dataset) {
NumberAxis xAxis = new NumberAxis("X");
xAxis.setLowerMargin(0.0);
xAxis.setUpperMargin(0.0);
NumberAxis yAxis = new NumberAxis("Y");
yAxis.setAutoRangeIncludesZero(false);
yAxis.setInverted(true);
yAxis.setLowerMargin(0.0);
yAxis.setUpperMargin(0.0);
yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
renderer = new XYBlockRenderer();
renderer.setBlockHeight(10);
renderer.setBlockWidth(10);
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
plot.setBackgroundPaint(Color.lightGray);
plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
JFreeChart chart = new JFreeChart("XYBlockChartDemo3", plot);
chart.removeLegend();
chart.setBackgroundPaint(Color.white);
CustomGrayPaintScale scale = new CustomGrayPaintScale(0,100);
renderer.setPaintScale(scale);
return chart;
}
private static void setValue(double[][] data, int c, int r, double value) {
data[0][(r) * 10 + c] = c;
data[1][(r) * 10 + c] = r;
data[2][(r) * 10 + c] = value;
}
/**
* Creates a sample dataset.
*/
private static XYZDataset createDataset() {
// set the default z-value to zero throughout the data array.
int count[][] = new int[10][10];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
count[i][j] = i * j;
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
setValue(data, j, i, count[i][j]);
}
}
DefaultXYZDataset dataset = new DefaultXYZDataset();
dataset.addSeries("Series 1", data);
return dataset;
}
public static ChartPanel createDemoPanel() {
return new ChartPanel(createChart(createDataset()));
}
public static void main(String[] args) {
blockRenderer("test");
}
}
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Trying to set the block height and width in XYBlockRende
Your data values have an increment of 1 both in x and y direction. The size of the blocks, i.e. the space that is covered by an item, is 10, both for the x and the y direction. So your items MUST overlap.
I am not sure what you expect to see.
I am not sure what you expect to see.
Re: Trying to set the block height and width in XYBlockRende
I expect all blocks to be of height and width as 10. Like the one visible, all must come that way only.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Trying to set the block height and width in XYBlockRende
How can the block starting at x=0 and y=0 and ending at x=10 and y=10 be visible if there is another 10x10 block starting at x=1 and y=1?
Re: Trying to set the block height and width in XYBlockRende
Okay. Correct. Thanks a lot, I now understood how exactly the renderer renders the block. I just need to multiply the r,c values with 10 in my setValue function(). It works good now 
Actually, when I wasn't setting any height and width, the blocks were getting divided as per the frame size. That's why I wanted to try and see how blockHeight and width changes that.

Actually, when I wasn't setting any height and width, the blocks were getting divided as per the frame size. That's why I wanted to try and see how blockHeight and width changes that.