Hi
Is there any way to display the data plotted shown along with the chart. I need it as a separate table . Not as the item label in each plot in chart .
X Y Value
10 10 100
20 20 200
30 30 300
40 40 400
50 50 500
Is there any way to do it.. Please help
Table data plotted along with chart
-
- Posts: 5
- Joined: Wed Apr 02, 2008 10:55 am
re:
Hi
As far as I knew ,we cannot get the data display beside the chart other than the labels and titles and subtitles.I also with the same issue.I dont know whether jfreecharts supports this feature.
As far as I knew ,we cannot get the data display beside the chart other than the labels and titles and subtitles.I also with the same issue.I dont know whether jfreecharts supports this feature.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
If you need the table to be part of the chart, you can use a nested BlockContainer with LabelBlocks. The example here uses the following approach:
The x values and y values are stored as LabelBlocks in two separate BlockContainers each having a ColumnArrangement.
These two BlockContainers are managed by a further main BlockContainer that has a FlowArrangement.
it is probably not the best approach. I tried to use a GridArrangement but that threw a "Not yet implemented" Exception
.
Enjoy.
The x values and y values are stored as LabelBlocks in two separate BlockContainers each having a ColumnArrangement.
These two BlockContainers are managed by a further main BlockContainer that has a FlowArrangement.
it is probably not the best approach. I tried to use a GridArrangement but that threw a "Not yet implemented" Exception

Enjoy.
Code: Select all
package demo;
import java.awt.Font;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.block.Arrangement;
import org.jfree.chart.block.BlockContainer;
import org.jfree.chart.block.ColumnArrangement;
import org.jfree.chart.block.FlowArrangement;
import org.jfree.chart.block.GridArrangement;
import org.jfree.chart.block.LabelBlock;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.CompositeTitle;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.ui.RectangleEdge;
public class ChartComponentDemo2{
private static Font smallfont;
private static Font bigfont;
public static void main(String[] args){
smallfont = new Font("Arial",0,12);
bigfont = new Font("Arial",0,16);
DefaultXYDataset set = new DefaultXYDataset();
double[][] data = new double[][]{{10.0d,20.0d,30.0d,40.0d},{1.0d,2.0d,3.0d,4.0d}};
set.addSeries("One",data);
NumberAxis xAxis = new NumberAxis("x axis");
xAxis.setLabelFont(smallfont);
NumberAxis yAxis = new NumberAxis("yaxis");
yAxis.setLabelFont(smallfont);
XYPlot xyplot = new XYPlot(set,xAxis,yAxis,new XYLineAndShapeRenderer(true,true));
JFreeChart chart = new JFreeChart(" The Chart",bigfont,xyplot,true);
String[][] stringtable = createStringTableData(set,0);
BlockContainer xValues = new BlockContainer(new ColumnArrangement());
BlockContainer yValues = new BlockContainer(new ColumnArrangement());
for(int i = 0; i < stringtable.length; i++){
xValues.add(new LabelBlock(stringtable[i][0]));
yValues.add(new LabelBlock(stringtable[i][1]));
}
BlockContainer mainBlock = new BlockContainer(new FlowArrangement());
mainBlock.add(xValues);
mainBlock.add(yValues);
CompositeTitle cTitle = new CompositeTitle(mainBlock);
cTitle.setPosition(RectangleEdge.RIGHT);
chart.addSubtitle(cTitle);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new ChartPanel(chart));
frame.pack();
frame.setVisible(true);
}
private static String[][] createStringTableData(XYDataset set,int seriesIndex){
String[][] data = new String[set.getItemCount(seriesIndex)][2];
for(int count = 0;count < set.getItemCount(seriesIndex);count++ ){
data[count][0] = String.valueOf(set.getXValue(seriesIndex,count));
data[count][1] = String.valueOf(set.getYValue(seriesIndex,count));
}
return data;
}
}