|
|
Create Dial chart | jfree | dashboard gauges| meters
This is an alternative to the meter chart   The requirement is the same as meter chart, your SQL should return only one column and one row, just a single cell value   select count(transactions) as runs from tbl_trans  
  When you first create the chart, it appears blank
  You need to enable the javascript and set the appropriate dial ranges and options   import org.jfree.chart.JFreeChart; import org.jfree.experimental.chart.plot.dial.DialPlot; import org.jfree.experimental.chart.plot.dial.SimpleDialFrame; import org.jfree.experimental.chart.plot.dial.DialTextAnnotation; import org.jfree.experimental.chart.plot.dial.StandardDialRange; import org.jfree.experimental.chart.plot.dial.StandardDialScale; import org.jfree.experimental.chart.plot.dial.DialBackground; import org.jfree.experimental.chart.plot.dial.DialCap; import org.jfree.experimental.chart.plot.dial.DialPointer; import org.jfree.experimental.chart.plot.dial.DialValueIndicator; import org.jfree.data.general.DefaultValueDataset; import org.jfree.ui.GradientPaintTransformType; import org.jfree.ui.StandardGradientPaintTransformer;
DialPlot plot = (DialPlot)(chart.getPlot()); SimpleDialFrame dialFrame = new SimpleDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.darkGray); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(0,90, 0)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(db); DialTextAnnotation annotation1 = new DialTextAnnotation("Runs"); annotation1.setFont(new Font("Dialog", Font.BOLD, 14)); annotation1.setRadius(0.7); plot.addLayer(annotation1); DialValueIndicator dvi = new DialValueIndicator(0, " "); plot.addLayer(dvi);   /* set the dial range and the angle of the inside circle for e.g 0 through 120 is the range of the values and the -120 is the starting angle and -300 is the ending angle in degrees.*/ StandardDialScale scale = new StandardDialScale(0, 120, -120, -300);   scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14)); plot.addScale(0, scale); StandardDialRange range = new StandardDialRange(0.0, 50.0, Color.green); range.setInnerRadius(0.52); range.setOuterRadius(0.58); plot.addLayer(range); StandardDialRange range2 = new StandardDialRange(50.0, 80.0, Color.blue); range2.setInnerRadius(0.52); range2.setOuterRadius(0.58); plot.addLayer(range2); StandardDialRange range3 = new StandardDialRange(80.0, 120.0, Color.red); range3.setInnerRadius(0.52); range3.setOuterRadius(0.58); plot.addLayer(range3); DialPointer needle = new DialPointer.Pointer(); plot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.1); plot.setCap(cap);
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,Color.blue,0,h, Color.cyan)); | ||||||||||||||||||||||||||||||||
|