|
|
Create Meter | gauge | speedometer | dial | jfree | chart | dashboards
  This is one of the most sought after chart. It is known by various names such as Gauges, Dials, Speedometer etc   To create this chart, your SQL should return only one column and one row   select sum(amount)/ 365 as avg_sales_per_day from [qb_data$] where "Account Type" = 'Income' and date between #12/1/2007# and #05/23/2008#   In the above query, the SQL has only one column avg_sales_per_day. The chart type should be 'Meter'  
  When you create the chart it appears in the default look and feel as shown below
  It appears in the default black background, there are no sections or the pointer.   You need to enable the javascript option and click on apply
  Click on the "Dynamic Java Code" and modify the script as necessary.       import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.DialShape; import org.jfree.chart.plot.MeterInterval; import org.jfree.chart.plot.MeterPlot; import org.jfree.data.Range;
MeterPlot plot = (MeterPlot)(chart.getPlot());   /* You need to set the range of the complete dial, in this case our range is from 0 to 14000 */ plot.setUnits("Sales/Day"); plot.setRange(new Range(0, 14000));
/* The next step is to add an interval in the Meter, our first range is from 0 to 5000 and we label this section to be critical we also indicate the color of this section using the RGB value new Color(255, 0, 0, 128) */ plot.addInterval(new MeterInterval("Critical", new Range(0.0, 5000.0), Color.lightGray, new BasicStroke(2.0f), new Color(255, 0, 0, 128)));
/* similarly you can add as many range or section but the final range should be ending in 14000 and all the ranges should be defined in sequential order for e.g. {0, 5000} , { 5000, 7000} , { 7000,14000} */ plot.addInterval(new MeterInterval("Warning", new Range(5000.0, 7000.0), Color.lightGray, new BasicStroke(2.0f), new Color(255, 255, 0,64)));
plot.addInterval(new MeterInterval("Good", new Range(7000.0, 14000.0), Color.lightGray, new BasicStroke(2.0f), new Color(0, 255, 0, 64)));
/* remaining properties are self explanatory */ plot.setNeedlePaint(Color.darkGray); plot.setDialBackgroundPaint(Color.white); plot.setDialOutlinePaint(Color.gray); plot.setDialShape(DialShape.CHORD); plot.setMeterAngle(260); plot.setTickLabelsVisible(true); plot.setTickLabelFont(new Font("Dialog", Font.BOLD, 10)); plot.setTickLabelPaint(Color.darkGray); plot.setTickSize(500.0); plot.setTickPaint(Color.lightGray);
plot.setValuePaint(Color.black); float h = displayFrame.getHeight(); float w = displayFrame.getWidth(); // GradientPaint gradientPaint = new GradientPaint(0.0F, 10.0F, Color.WHITE, h, w, Color.green.darker()); //plot.setBackgroundPaint(gradientPaint);
chart.setBackgroundPaint(new GradientPaint(0,0,new Color(102,0,102),0,h,Color.black ));
chart.getTitle().setPaint(Color.white); plot.setValueFont(new Font("Dialog", Font.BOLD, 14));   | ||||||||||||||||||||||||||||||||
|