I have an issue with JFreeChart
in Redhat 6.5. My chart is flipped top-for-bottom.
This is my source code to add chart.
private Control createPartControl() {
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
ScrolledComposite sc = new ScrolledComposite(m_parent, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setLayoutData(layoutData);
sc.setMinSize(450, 250);
m_mainComposite = new Composite(sc, SWT.EMBEDDED);
m_mainComposite.setLayoutData(layoutData);
m_mainComposite.setBackground(ColorConstants.white);
Frame frame = SWT_AWT.new_Frame(m_mainComposite);
frame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
m_panel.setMaximumDrawHeight(e.getComponent().getHeight());
m_panel.setMaximumDrawWidth(e.getComponent().getWidth());
m_panel.setMinimumDrawWidth(e.getComponent().getWidth());
m_panel.setMinimumDrawHeight(e.getComponent().getHeight());
}
});
m_panel = new ChartPanel(null);
m_panel.setPopupMenu(null);
frame.add(m_panel);
frame.setBackground(Color.white);
sc.setContent(m_mainComposite);
return sc;
}
public void updateContent(List<AggregatedSdcCollectionStat> stats) {
if (!isChartExsited()) {
m_chart = createChart(createDataset(stats));
m_panel.setChart(m_chart);
setChartExisted(true);
//m_panel.setVisible(true);
}
}
private JFreeChart createChart(CategoryDataset categorydataset) {
String collectionTime = Messages.getString("SdcCollectionStatisticViewItem.chart.xAxis");//$NON-NLS-1$
String nes = Messages.getString("SdcCollectionStatisticViewItem.chart.yAxis");//$NON-NLS-1$
JFreeChart jfreechart = ChartFactory
.createStackedBarChart(null, collectionTime, nes, categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
categoryplot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
stackedbarrenderer.setDrawBarOutline(false);
stackedbarrenderer.setBaseItemLabelsVisible(true);
stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
CategoryItemRenderer renderer = categoryplot.getRenderer();
renderer.setSeriesPaint(0, SUCCESS_CLR);
renderer.setSeriesPaint(1, ONGOING_CLR);
renderer.setSeriesPaint(2, MISSING_CLR);
renderer.setSeriesPaint(3, EXCLUDED_CLR);
renderer.setBaseItemLabelsVisible(Boolean.FALSE);
return jfreechart;
}
Executing the jar:
java -jar jfreechart-1.0.2-demo.jar
Console output:
Exception in thread "main"
java.lang.NoClassDefFoundError:org/jfree/ui/ApplicationFrame Caused by:
java.lang.ClassNotFoundException: org.jfree.ui.ApplicationFrame at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:423)
This only happens with Redhat; it works fine on Windows and Ubuntu. Did you see this issue? Can you give me a solution for this case?