Feb 18
Speedometer with JFreeChart in Eclipse
Tags: charts, development, eclipse, software, tools, visualization Add comments
There is a great tutorial on vogella.de describing how to add a pie chart with JFreeChart to an Eclipse RCP application or plug-in. The ChartFactory that is used to create the pie chart does not include a method to create a speedometer (or dial) as shown in the sample section of JFreeChart. The following code fragment creates a view that displays a very basic speedometer using the org.jfree.chart.plot.MeterPlot class:
package com.martinklinke.eclipse.jfreechart.demo.views; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.ViewPart; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.MeterPlot; import org.jfree.data.general.DefaultValueDataset; import org.jfree.experimental.chart.swt.ChartComposite; /** * @author martin * */ public class MeterChartView extends ViewPart { public static final String ID = "com.martinklinke.eclipse.jfreechart.demo.views.MeterChartView"; public void createPartControl(Composite parent) { JFreeChart chart = createChart(); final ChartComposite frame = new ChartComposite(parent, SWT.NONE, chart, true); } public void setFocus() { } /** * Creates the Chart based on a dataset */ private JFreeChart createChart() { DefaultValueDataset data = new DefaultValueDataset(20.0); MeterPlot plot = new MeterPlot(data); JFreeChart chart = new JFreeChart("Meter Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); plot.setNoDataMessage("No data available"); return chart; } } |
The result should look like the following screenshot:
Of course, the MeterPlot can be further customized by calling the plot.setXXX(…) methods. However, this exercise is left to the willing reader ;)
June 6th, 2011 at 3:40 pm
can you explain me how to configure the units in the middle of the meter chart and how to provide max and min values….i want to assign the max and minimum values could you please help me out in configuring the max and minimum values to assign to meter chart.. to my mail id… thank you.