Properties- dialog
-
- Posts: 81
- Joined: Wed Jul 25, 2007 10:40 am
Properties- dialog
Hello,
is it possible to add a tab to the chart- properties- dialog (right mouse button onto the chart -> first item properties)
By default there are 3 tabs -> headline, diagramm an others,
Thanks a lot for responses,
All the best,
is it possible to add a tab to the chart- properties- dialog (right mouse button onto the chart -> first item properties)
By default there are 3 tabs -> headline, diagramm an others,
Thanks a lot for responses,
All the best,
-
- Posts: 81
- Joined: Wed Jul 25, 2007 10:40 am
There was some earlier discussion about this topic:
Poor newbies can't post URLs though... topic ID is 22660
I was going to add an Excel like "Series" editor for my plots by adding a tab for this in the chart editor, but I think I have decided to make a separate dialog altogether to do this instead of modifying ChartEditor.
Haven't started yet, but it sounds easy enough.
Poor newbies can't post URLs though... topic ID is 22660
I was going to add an Excel like "Series" editor for my plots by adding a tab for this in the chart editor, but I think I have decided to make a separate dialog altogether to do this instead of modifying ChartEditor.
Haven't started yet, but it sounds easy enough.

-
- Posts: 47
- Joined: Thu Dec 11, 2008 7:59 pm
The general order of operation when you click on Properties...
- The DefaultChartEditorFactory creates a DefaultChartEditor with the JFreeChart that you are editing.
- The DefaultChartEditor builds a JPanel full of options for the user to play with.
- The updateChart method applies the user selections when the user clicks OK.
What you can do is take his existing chart editor and then modify it to meet your own needs. You will replace the DefaultChartEditorFactory and DefaultChartEditor with your own versions. You will need the JFreeChart source code included with the download.
1) Grab a copy of his chart editor. It’s located at JFreeChart.zip\source\org\jfree\chart\editor. There are 12 Java files, 10 Properties files, and a HTML file. You need everything except the HTML file. (The Properties files are for language localization, HTML file is for Javadoc).
2) Put the Java and Properties files into a folder in the source code for your program, for example my\java\app\myeditor.
3) Rename the file DefaultChartEditorFactory.java to MyChartEditorFactory.java. Open it and rename every occurrence of Default with My.
4) Rename the file DefaultChartEditor.java to MyChartEditor.java. Open it and rename references of DefaultChartEditor to MyChartEditor. Do NOT change anything related to the DefaultAxisEditor, DefaultColorBarEditor, DefaultNumberAxisEditor, DefaultPlotEditor, DefaultTitleEditor. Those we will leave alone for now.
5) At this point we can test to see if your program can use your local chart editor instead of his. In your main class, add an import statement to include your local chart editor Then somewhere, usually in the main() or Constructor, call Compile and run. You may get deprecated warnings; ignore them for now. The chart editor should be the same as before, but now it is your local copy.
6) Now you can modify the chart editor to your own needs. The top level file to start modifying is MyChartEditor.java. This is the JPanel that holds everything together, it is responsible for the tabs, where each tab is another JPanel contained in one of: DefaultAxisEditor.java, DefaultColorBarEditor.java, DefaultNumberAxisEditor.java, DefaultPlotEditor.java, DefaultTitleEditor.java. So start by modifying MyChartEditor.java and any sub JPanel you need.
- The DefaultChartEditorFactory creates a DefaultChartEditor with the JFreeChart that you are editing.
- The DefaultChartEditor builds a JPanel full of options for the user to play with.
- The updateChart method applies the user selections when the user clicks OK.
What you can do is take his existing chart editor and then modify it to meet your own needs. You will replace the DefaultChartEditorFactory and DefaultChartEditor with your own versions. You will need the JFreeChart source code included with the download.
1) Grab a copy of his chart editor. It’s located at JFreeChart.zip\source\org\jfree\chart\editor. There are 12 Java files, 10 Properties files, and a HTML file. You need everything except the HTML file. (The Properties files are for language localization, HTML file is for Javadoc).
2) Put the Java and Properties files into a folder in the source code for your program, for example my\java\app\myeditor.
3) Rename the file DefaultChartEditorFactory.java to MyChartEditorFactory.java. Open it and rename every occurrence of Default with My.
Code: Select all
package my.java.app.myeditor;
import org.jfree.chart.*;
import org.jfree.chart.editor.*;
/**
* My implementation of the ChartEditorFactory interface.
*/
public class MyChartEditorFactory implements ChartEditorFactory
{
/**
* Creates a new instance.
*/
public MyChartEditorFactory()
{
}
/**
* Returns a new instance of a ChartEditor.
*
* @param chart the chart.
*
* @return A chart editor for the given chart.
*/
public ChartEditor createEditor(JFreeChart chart)
{
return new MyChartEditor(chart);
}
}
Code: Select all
package my.java.app.myeditor;
import java.awt.*;
import javax.swing.*;
import org.jfree.chart.*;
import org.jfree.chart.editor.*;
import org.jfree.chart.plot.*;
/**
* A panel for editing chart properties.
*/
class MyChartEditor extends JPanel implements ChartEditor
{
/**
* Constructs a panel for editing the specified chart.
*/
public MyChartEditor(JFreeChart chart)
{
....
}
}
Code: Select all
import my.java.app.myeditor;
Code: Select all
ChartEditorManager.setChartEditorFactory(new MyChartEditorFactory());
6) Now you can modify the chart editor to your own needs. The top level file to start modifying is MyChartEditor.java. This is the JPanel that holds everything together, it is responsible for the tabs, where each tab is another JPanel contained in one of: DefaultAxisEditor.java, DefaultColorBarEditor.java, DefaultNumberAxisEditor.java, DefaultPlotEditor.java, DefaultTitleEditor.java. So start by modifying MyChartEditor.java and any sub JPanel you need.
-
- Posts: 81
- Joined: Wed Jul 25, 2007 10:40 am
Hi MitchBuell,
I did it step by step like in your description but it doesn't work.
It doesn't use my editor:
Behind is the code of mine, do you have any idea, whats wrong?
Do I have to set the ChartEditorManager onto my chart- panel,
My opinion is that jfreechart uses the internal editor instead of mine.
Thanks a lot,
all the best,
Poller
I did it step by step like in your description but it doesn't work.
It doesn't use my editor:
Behind is the code of mine, do you have any idea, whats wrong?
Do I have to set the ChartEditorManager onto my chart- panel,
My opinion is that jfreechart uses the internal editor instead of mine.
Thanks a lot,
all the best,
Poller
Code: Select all
public ChartPanel getChart() { // this methode is invoked to create the freechartpanel
chart = createChart();
chart.addChangeListener(new TrendZoomListener(plot));
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
chartPanel = new MyChartPanel(chart, traceView);
chartPanel.setPreferredSize(new java.awt.Dimension(600, 270));
chartPanel.setDomainZoomable(true);
chartPanel.setRangeZoomable(true);
chartPanel.setName(mainTitle);
chartPanel.getPopupMenu().getComponent();
MyChartEditorFactory cef = new MyChartEditorFactory(); // here are the important lines
ChartEditorManager.setChartEditorFactory(cef);
return chartPanel;
}
-
- Posts: 47
- Joined: Thu Dec 11, 2008 7:59 pm
First thing to do: move the
out of getChart() and into your public static void main(String[] args) or Constructor. These two lines have to be called before you make your chart.
Here's a quick demo application that works with my own chart editor. I set my chart editor before I use any other JFreeChart stuff.
Code: Select all
MyChartEditorFactory cef = new MyChartEditorFactory(); // here are the important lines
ChartEditorManager.setChartEditorFactory(cef);
Here's a quick demo application that works with my own chart editor. I set my chart editor before I use any other JFreeChart stuff.
Code: Select all
package demo;
import javax.swing.*;
import org.jfree.chart.*;
import org.jfree.chart.editor.ChartEditorManager; // For ChartEditorManager.setChartEditorFactory()
import org.jfree.chart.plot.*;
import org.jfree.data.xy.*;
import demo.myeditor.MyChartEditorFactory; // My chart editor
public class Demo
{
public static void main(String[] args)
{
// Tell JFreeChart to use my chart editor
ChartEditorManager.setChartEditorFactory(new MyChartEditorFactory());
// Make a demo series
XYSeries series1 = new XYSeries("Series1");
for (int i = 0; i < 10; ++i)
series1.add(i, Math.random());
XYSeriesCollection collection = new XYSeriesCollection();
collection.addSeries(series1);
// Make a demo chart
JFreeChart chart = ChartFactory.createXYLineChart(
"Chart Editor Demo",
"X",
"Y",
collection,
PlotOrientation.VERTICAL,
true,
true,
false
);
ChartPanel chartPanel = new ChartPanel(chart);
JFrame frame = new JFrame("Demo");
frame.add(chartPanel);
frame.pack();
frame.setVisible(true);
}
}
-
- Posts: 81
- Joined: Wed Jul 25, 2007 10:40 am
-
- Posts: 81
- Joined: Wed Jul 25, 2007 10:40 am
Yes, of course, but I got the exception:MitchBuell wrote:Did you try to run my Demo application?
Code: Select all
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at demo.myeditor.MyChartEditorFactory.createEditor(MyChartEditorFactory.java:73)
at org.jfree.chart.editor.ChartEditorManager.getChartEditor(ChartEditorManager.java:94)
at org.jfree.chart.ChartPanel.doEditChartProperties(ChartPanel.java:2108)
at org.jfree.chart.ChartPanel.actionPerformed(ChartPanel.java:1330)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
Code: Select all
package demo.myeditor;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.editor.ChartEditor;
public class MyChartEditorFactory implements org.jfree.chart.editor.ChartEditorFactory {
public MyChartEditorFactory() {
System.out.println("Das ist der Konstruktor MyChartEditorFactory");
}
public ChartEditor createEditor(JFreeChart chart) {
System.out.println("*** createEditor in der Klasse MyChartEditorFactory");
return new MyChartEditor(chart); // here I get the fault!!!
}
}
All the best,
Poller
-
- Posts: 81
- Joined: Wed Jul 25, 2007 10:40 am