org.jfree.chart.plot.dial.DialPlot Java Examples

The following examples show how to use org.jfree.chart.plot.dial.DialPlot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial frame.
 */
public void testFrameListener() {
    DialPlot p = new DialPlot();
    ArcDialFrame f1 = new ArcDialFrame();
    p.setDialFrame(f1);
    p.addChangeListener(this);
    this.lastEvent = null;
    f1.setBackgroundPaint(Color.gray);
    assertNotNull(this.lastEvent);

    ArcDialFrame f2 = new ArcDialFrame();
    p.setDialFrame(f2);
    this.lastEvent = null;
    f1.setBackgroundPaint(Color.blue);
    assertNull(this.lastEvent);
    f2.setBackgroundPaint(Color.green);
    assertNotNull(this.lastEvent);
}
 
Example #2
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for a layer.
 */
public void testLayerListener() {
    DialPlot p = new DialPlot();
    DialBackground b1 = new DialBackground(Color.red);
    p.addLayer(b1);
    p.addChangeListener(this);
    this.lastEvent = null;
    b1.setPaint(Color.blue);
    assertNotNull(this.lastEvent);
    
    DialBackground b2 = new DialBackground(Color.green);
    p.addLayer(b2);
    this.lastEvent = null;
    b1.setPaint(Color.red);
    assertNotNull(this.lastEvent);
    b2.setPaint(Color.green);
    assertNotNull(this.lastEvent);
    
    p.removeLayer(b2);
    this.lastEvent = null;
    b2.setPaint(Color.red);
    assertNull(this.lastEvent);   
}
 
Example #3
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial scales.
 */
public void testScaleListener() {
    DialPlot p = new DialPlot();
    StandardDialScale s1 = new StandardDialScale();
    p.addScale(0, s1);
    p.addChangeListener(this);
    this.lastEvent = null;
    s1.setStartAngle(22.0);
    assertNotNull(this.lastEvent);
    
    StandardDialScale s2 = new StandardDialScale();
    p.addScale(0, s2);
    this.lastEvent = null;
    s1.setStartAngle(33.0);
    assertNull(this.lastEvent);
    s2.setStartAngle(33.0);
    assertNotNull(this.lastEvent);
}
 
Example #4
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial frame.
 */
public void testFrameListener() {
    DialPlot p = new DialPlot();
    ArcDialFrame f1 = new ArcDialFrame();
    p.setDialFrame(f1);
    p.addChangeListener(this);
    this.lastEvent = null;
    f1.setBackgroundPaint(Color.gray);
    assertNotNull(this.lastEvent);
    
    ArcDialFrame f2 = new ArcDialFrame();
    p.setDialFrame(f2);
    this.lastEvent = null;
    f1.setBackgroundPaint(Color.blue);
    assertNull(this.lastEvent);
    f2.setBackgroundPaint(Color.green);
    assertNotNull(this.lastEvent);
}
 
Example #5
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial cap.
 */
public void testCapListener() {
    DialPlot p = new DialPlot();
    DialCap c1 = new DialCap();
    p.setCap(c1);
    p.addChangeListener(this);
    this.lastEvent = null;
    c1.setFillPaint(Color.red);
    assertNotNull(this.lastEvent);
    
    DialCap c2 = new DialCap();
    p.setCap(c2);
    this.lastEvent = null;
    c1.setFillPaint(Color.blue);
    assertNull(this.lastEvent);
    c2.setFillPaint(Color.green);
    assertNotNull(this.lastEvent);
}
 
Example #6
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial background.
 */
public void testBackgroundListener() {
    DialPlot p = new DialPlot();
    DialBackground b1 = new DialBackground(Color.red);
    p.setBackground(b1);
    p.addChangeListener(this);
    this.lastEvent = null;
    b1.setPaint(Color.blue);
    assertNotNull(this.lastEvent);
    
    DialBackground b2 = new DialBackground(Color.green);
    p.setBackground(b2);
    this.lastEvent = null;
    b1.setPaint(Color.red);
    assertNull(this.lastEvent);
    b2.setPaint(Color.red);
    assertNotNull(this.lastEvent);
}
 
Example #7
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for a layer.
 */
public void testLayerListener() {
    DialPlot p = new DialPlot();
    DialBackground b1 = new DialBackground(Color.red);
    p.addLayer(b1);
    p.addChangeListener(this);
    this.lastEvent = null;
    b1.setPaint(Color.blue);
    assertNotNull(this.lastEvent);

    DialBackground b2 = new DialBackground(Color.green);
    p.addLayer(b2);
    this.lastEvent = null;
    b1.setPaint(Color.red);
    assertNotNull(this.lastEvent);
    b2.setPaint(Color.green);
    assertNotNull(this.lastEvent);

    p.removeLayer(b2);
    this.lastEvent = null;
    b2.setPaint(Color.red);
    assertNull(this.lastEvent);
}
 
Example #8
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial scales.
 */
public void testScaleListener() {
    DialPlot p = new DialPlot();
    StandardDialScale s1 = new StandardDialScale();
    p.addScale(0, s1);
    p.addChangeListener(this);
    this.lastEvent = null;
    s1.setStartAngle(22.0);
    assertNotNull(this.lastEvent);

    StandardDialScale s2 = new StandardDialScale();
    p.addScale(0, s2);
    this.lastEvent = null;
    s1.setStartAngle(33.0);
    assertNull(this.lastEvent);
    s2.setStartAngle(33.0);
    assertNotNull(this.lastEvent);
}
 
Example #9
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial cap.
 */
public void testCapListener() {
    DialPlot p = new DialPlot();
    DialCap c1 = new DialCap();
    p.setCap(c1);
    p.addChangeListener(this);
    this.lastEvent = null;
    c1.setFillPaint(Color.red);
    assertNotNull(this.lastEvent);

    DialCap c2 = new DialCap();
    p.setCap(c2);
    this.lastEvent = null;
    c1.setFillPaint(Color.blue);
    assertNull(this.lastEvent);
    c2.setFillPaint(Color.green);
    assertNotNull(this.lastEvent);
}
 
Example #10
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check the notification event mechanism for the dial background.
 */
public void testBackgroundListener() {
    DialPlot p = new DialPlot();
    DialBackground b1 = new DialBackground(Color.red);
    p.setBackground(b1);
    p.addChangeListener(this);
    this.lastEvent = null;
    b1.setPaint(Color.blue);
    assertNotNull(this.lastEvent);

    DialBackground b2 = new DialBackground(Color.green);
    p.setBackground(b2);
    this.lastEvent = null;
    b1.setPaint(Color.red);
    assertNull(this.lastEvent);
    b2.setPaint(Color.red);
    assertNotNull(this.lastEvent);
}
 
Example #11
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashCode() {
    DialPlot p1 = new DialPlot();
    DialPlot p2 = new DialPlot();
    assertTrue(p1.equals(p2));
    int h1 = p1.hashCode();
    int h2 = p2.hashCode();
    assertEquals(h1, h2);
}
 
Example #12
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashCode() {
    DialPlot p1 = new DialPlot();
    DialPlot p2 = new DialPlot();
    assertTrue(p1.equals(p2));
    int h1 = p1.hashCode();
    int h2 = p2.hashCode();
    assertEquals(h1, h2);
}
 
Example #13
Source File: ScaledDialRange.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Draws the range.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
		Rectangle2D view) {
	
	Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, 
			this.getInnerRadius(), this.getInnerRadius());
	Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, 
			this.getOuterRadius(), this.getOuterRadius());
	
	DialScale scale = plot.getScale(this.getScaleIndex());
	if (scale == null) {
		throw new RuntimeException("No scale for scaleIndex = " 
				+ this.getScaleIndex());
	}
	double angleMin = scale.valueToAngle(this.getLowerBound());
	double angleMax = scale.valueToAngle(this.getUpperBound());

	Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, 
			angleMax - angleMin, Arc2D.OPEN);
	Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, 
			angleMin - angleMax, Arc2D.OPEN);
	
	g2.setPaint(this.getPaint());
	g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
	g2.draw(arcInner);
	g2.draw(arcOuter);
}
 
Example #14
Source File: UnitStatusPage.java    From freeacs with MIT License 4 votes vote down vote up
/**
 * Creates a chart displaying a circular dial.
 *
 * @param chartTitle the chart title.
 * @param dialLabel the dial label.
 * @param dataset the dataset.
 * @param lowerBound the lower bound.
 * @param upperBound the upper bound.
 * @return A chart that displays a value as a dial.
 */
private JFreeChart createStatusDialChart(
    String chartTitle,
    String dialLabel,
    ValueDataset dataset,
    double lowerBound,
    double upperBound) {
  DialPlot plot = new DialPlot();
  plot.setDataset(dataset);
  plot.setDialFrame(new StandardDialFrame());
  DialTextAnnotation annotation1 = new DialTextAnnotation(dialLabel);
  annotation1.setFont(new Font("Dialog", Font.BOLD, 14));
  annotation1.setRadius(0.7);

  plot.addLayer(annotation1);

  DialValueIndicator dvi = new DialValueIndicator(0);
  plot.addLayer(dvi);

  StandardDialScale scale = new StandardDialScale(lowerBound, upperBound, -120, -300, 1, 4);
  scale.setTickRadius(0.88);
  scale.setTickLabelOffset(0.15);
  scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14));
  plot.addScale(0, scale);

  plot.addPointer(new DialPointer.Pin());

  DialCap cap = new DialCap();
  plot.setCap(cap);

  JFreeChart chart = new JFreeChart(chartTitle, plot);
  chart.setBackgroundPaint(Color.WHITE);

  StandardDialRange range =
      new StandardDialRange(UnitStatusInfo.DIAL_CHART_YELLOW, upperBound, Color.green);
  range.setInnerRadius(0.52);
  range.setOuterRadius(0.55);
  plot.addLayer(range);

  StandardDialRange range2 =
      new StandardDialRange(
          UnitStatusInfo.DIAL_CHART_RED, UnitStatusInfo.DIAL_CHART_YELLOW, Color.orange);
  range2.setInnerRadius(0.52);
  range2.setOuterRadius(0.55);
  plot.addLayer(range2);

  StandardDialRange range3 =
      new StandardDialRange(lowerBound, UnitStatusInfo.DIAL_CHART_RED, Color.red);
  range3.setInnerRadius(0.52);
  range3.setOuterRadius(0.55);
  plot.addLayer(range3);

  GradientPaint gp =
      new GradientPaint(
          new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220));
  DialBackground db = new DialBackground(gp);
  db.setGradientPaintTransformer(
      new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
  plot.setBackground(db);

  plot.removePointer(0);
  DialPointer.Pointer p = new DialPointer.Pointer();
  plot.addPointer(p);

  return chart;
}
 
Example #15
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    DialPlot p1 = new DialPlot();
    DialPlot p2 = new DialPlot();
    assertTrue(p1.equals(p2));

    // background
    p1.setBackground(new DialBackground(Color.green));
    assertFalse(p1.equals(p2));
    p2.setBackground(new DialBackground(Color.green));
    assertTrue(p1.equals(p2));

    p1.setBackground(null);
    assertFalse(p1.equals(p2));
    p2.setBackground(null);
    assertTrue(p1.equals(p2));

    // dial cap
    DialCap cap1 = new DialCap();
    cap1.setFillPaint(Color.red);
    p1.setCap(cap1);
    assertFalse(p1.equals(p2));
    DialCap cap2 = new DialCap();
    cap2.setFillPaint(Color.red);
    p2.setCap(cap2);
    assertTrue(p1.equals(p2));

    p1.setCap(null);
    assertFalse(p1.equals(p2));
    p2.setCap(null);
    assertTrue(p1.equals(p2));

    // frame
    StandardDialFrame f1 = new StandardDialFrame();
    f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
            4.0f, Color.white));
    p1.setDialFrame(f1);
    assertFalse(p1.equals(p2));
    StandardDialFrame f2 = new StandardDialFrame();
    f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
            4.0f, Color.white));
    p2.setDialFrame(f2);
    assertTrue(p1.equals(p2));

    // view
    p1.setView(0.2, 0.0, 0.8, 1.0);
    assertFalse(p1.equals(p2));
    p2.setView(0.2, 0.0, 0.8, 1.0);
    assertTrue(p1.equals(p2));

    // layer
    p1.addLayer(new StandardDialScale());
    assertFalse(p1.equals(p2));
    p2.addLayer(new StandardDialScale());
    assertTrue(p1.equals(p2));
}
 
Example #16
Source File: DialPlotTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    DialPlot p1 = new DialPlot();
    DialPlot p2 = new DialPlot();
    assertTrue(p1.equals(p2));
    
    // background
    p1.setBackground(new DialBackground(Color.green));
    assertFalse(p1.equals(p2));
    p2.setBackground(new DialBackground(Color.green));
    assertTrue(p1.equals(p2));
    
    p1.setBackground(null);
    assertFalse(p1.equals(p2));
    p2.setBackground(null);
    assertTrue(p1.equals(p2));
    
    // dial cap
    DialCap cap1 = new DialCap();
    cap1.setFillPaint(Color.red);
    p1.setCap(cap1);
    assertFalse(p1.equals(p2));
    DialCap cap2 = new DialCap();
    cap2.setFillPaint(Color.red);
    p2.setCap(cap2);
    assertTrue(p1.equals(p2));
    
    p1.setCap(null);
    assertFalse(p1.equals(p2));
    p2.setCap(null);
    assertTrue(p1.equals(p2));
    
    // frame
    StandardDialFrame f1 = new StandardDialFrame();
    f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 
            4.0f, Color.white));
    p1.setDialFrame(f1);
    assertFalse(p1.equals(p2));
    StandardDialFrame f2 = new StandardDialFrame();
    f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 
            4.0f, Color.white));
    p2.setDialFrame(f2);
    assertTrue(p1.equals(p2));
    
    // view
    p1.setView(0.2, 0.0, 0.8, 1.0);
    assertFalse(p1.equals(p2));
    p2.setView(0.2, 0.0, 0.8, 1.0);
    assertTrue(p1.equals(p2));
    
    // layer
    p1.addLayer(new StandardDialScale());
    assertFalse(p1.equals(p2));
    p2.addLayer(new StandardDialScale());
    assertTrue(p1.equals(p2));
}
 
Example #17
Source File: CommonMeterChartAction.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
private void fillChart(String title, float value, int lowerBound, int upperBound) throws Exception {
	DefaultValueDataset dataset = new DefaultValueDataset();
	
	dataset.setValue(value);

	DialPlot plot = new DialPlot();
	plot.setView(0.0d, 0.0d, 1.0d, 1.0d);
	plot.setDataset(0, dataset);
	
	StandardDialFrame frame = new StandardDialFrame();
	plot.setDialFrame(frame);
	DialBackground dialBackground = new DialBackground();
	dialBackground.setGradientPaintTransformer(
			new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
	plot.setBackground(dialBackground);
	DialTextAnnotation textAnnotation = new DialTextAnnotation( title );
	textAnnotation.setRadius(0.555555555555555555D);
	plot.addLayer(textAnnotation);
	
	DialValueIndicator valueIndicator = new DialValueIndicator(0);
	plot.addLayer(valueIndicator);
	
	StandardDialScale scale1 = new StandardDialScale();
	scale1.setLowerBound( lowerBound );
	scale1.setUpperBound( upperBound );
	scale1.setStartAngle( -140 ); // -120
	scale1.setExtent( -260D ); // -300D 
	scale1.setTickRadius(0.88D);
	scale1.setTickLabelOffset(0.14999999999999999D); 
	scale1.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 14)); 
	plot.addScale(0, scale1);
	
	StandardDialRange standarddialrange0 = new StandardDialRange( lowerBound, (upperBound*0.6), Color.red);
	standarddialrange0.setInnerRadius(0.52000000000000002D);
	standarddialrange0.setOuterRadius(0.55000000000000004D);
	plot.addLayer(standarddialrange0);
	
	StandardDialRange standarddialrange1 = new StandardDialRange( (upperBound*0.6), (upperBound*0.8), Color.orange);
	standarddialrange1.setInnerRadius(0.52000000000000002D);
	standarddialrange1.setOuterRadius(0.55000000000000004D);
	plot.addLayer(standarddialrange1);
	
	StandardDialRange standarddialrange2 = new StandardDialRange( (upperBound*0.8), upperBound, Color.green);
	standarddialrange2.setInnerRadius(0.52000000000000002D);
	standarddialrange2.setOuterRadius(0.55000000000000004D);
	plot.addLayer(standarddialrange2);
	
	Pointer pointer = new Pointer(0); 
	pointer.setFillPaint(new Color(144, 196, 246));
	plot.addPointer(pointer);
	plot.mapDatasetToScale(0, 0);
	DialCap dialcap = new DialCap();
	dialcap.setRadius(0.0700000000000001D);
	plot.setCap(dialcap);
	
	this.chart = new JFreeChart(plot);
	//this.chart.setBackgroundPaint(new Color(234, 244, 253));
	this.chart.setBackgroundPaint( Color.white );
}
 
Example #18
Source File: ScaledDialValueIndicator.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
		Rectangle2D view) {

	// work out the anchor point
	Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(),
			this.getRadius());
	Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN);
	Point2D pt = arc.getStartPoint();

	// calculate the bounds of the template value
	FontMetrics fm = g2.getFontMetrics(this.getFont());
	String s = this.getNumberFormat().format(this.getTemplateValue());
	Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

	// align this rectangle to the frameAnchor
	Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(
			tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(),
			this.getFrameAnchor());

	// add the insets
	Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds);

	// draw the background
	g2.setPaint(this.getBackgroundPaint());
	g2.fill(fb);

	// draw the border
	g2.setStroke(this.getOutlineStroke());
	g2.setPaint(this.getOutlinePaint());
	g2.draw(fb);


	// now find the text anchor point
	String valueStr = this.getNumberFormat().format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale));
	Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor());
	g2.setPaint(this.getPaint());
	g2.setFont(this.getFont());
	TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(),
			(float) pt2.getY(), this.getTextAnchor());

}
 
Example #19
Source File: ScaledDialScale.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
		Rectangle2D view) {
	
	Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 
			this.getTickRadius(), this.getTickRadius());
	Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame, 
			this.getTickRadius() - this.getMajorTickLength(), 
			this.getTickRadius() - this.getMajorTickLength());
	Rectangle2D arcRectMinor = arcRect;
	if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
		arcRectMinor = DialPlot.rectangleByRadius(frame, 
				this.getTickRadius() - this.getMinorTickLength(), 
				this.getTickRadius() - this.getMinorTickLength());
	}
	Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, 
			this.getTickRadius() - this.getTickLabelOffset(), 
			this.getTickRadius() - this.getTickLabelOffset());
	
	boolean firstLabel = true;
	
	Arc2D arc = new Arc2D.Double();
	Line2D workingLine = new Line2D.Double();
	Stroke arcStroke = new BasicStroke(0.75f);
	
	for (double v = this.getLowerBound(); v <= this.getUpperBound(); 
			v += this.getMajorTickIncrement()) {
		arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) 
				- this.getStartAngle(), Arc2D.OPEN);
		g2.setPaint(this.getMajorTickPaint());
		g2.setStroke(arcStroke);
		g2.draw(arc);
		
		Point2D pt0 = arc.getEndPoint();
		arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) 
				- this.getStartAngle(), Arc2D.OPEN);
		Point2D pt1 = arc.getEndPoint();
		g2.setPaint(this.getMajorTickPaint());
		g2.setStroke(this.getMajorTickStroke());
		workingLine.setLine(pt0, pt1);
		g2.draw(workingLine);
		arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) 
				- this.getStartAngle(), Arc2D.OPEN);
		Point2D pt2 = arc.getEndPoint();
		
		if (this.getTickLabelsVisible()) {
			if (!firstLabel || this.getFirstTickLabelVisible()) {
				g2.setFont(this.getTickLabelFont());
				TextUtilities.drawAlignedString(
						this.getTickLabelFormatter().format(v), g2, 
						(float) pt2.getX(), (float) pt2.getY(), 
						TextAnchor.CENTER);
			}
		}
		firstLabel = false;
		
		// now do the minor tick marks
		if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
			double minorTickIncrement = this.getMajorTickIncrement() 
					/ (this.getMinorTickCount() + 1);
			for (int i = 0; i < this.getMinorTickCount(); i++) {
				double vv = v + ((i + 1) * minorTickIncrement);
				if (vv >= this.getUpperBound()) {
					break;
				}
				double angle = valueToAngle(vv);

				arc.setArc(arcRect, this.getStartAngle(), angle 
						- this.getStartAngle(), Arc2D.OPEN);
				pt0 = arc.getEndPoint();
				arc.setArc(arcRectMinor, this.getStartAngle(), angle 
						- this.getStartAngle(), Arc2D.OPEN);
				Point2D pt3 = arc.getEndPoint();
				g2.setStroke(this.getMinorTickStroke());
				g2.setPaint(this.getMinorTickPaint());
				workingLine.setLine(pt0, pt3);
				g2.draw(workingLine);
			}
		}
		
	}
}
 
Example #20
Source File: SBISpeedometer.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
	 * Creates a chart of type speedometer.
	 * 
	 * @param chartTitle  the chart title.
	 * @param dataset  the dataset.
	 * 
	 * @return A chart speedometer.
	 */

	public JFreeChart createChart(DatasetMap datasets) {
		logger.debug("IN");
		Dataset dataset=(Dataset)datasets.getDatasets().get("1");

		DialPlot plot = new DialPlot();
		plot.setDataset((ValueDataset)dataset);
		plot.setDialFrame(new StandardDialFrame());

		plot.setBackground(new DialBackground());
		if(dialtextuse){
			DialTextAnnotation annotation1 = new DialTextAnnotation(dialtext);			
			annotation1.setFont(styleTitle.getFont());
			annotation1.setRadius(0.7);

			plot.addLayer(annotation1);
		}

		DialValueIndicator dvi = new DialValueIndicator(0);
		dvi.setFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));
		dvi.setPaint(labelsValueStyle.getColor());
		plot.addLayer(dvi);

		StandardDialScale scale = new StandardDialScale(lower, 
				upper, -120, -300, 10.0, 4);

		if (!( increment > 0)){
			logger.warn("increment cannot be less than 0, put default to 0.1");
			increment = 0.01;
		}

		scale.setMajorTickIncrement(increment);

//		if (!( minorTickCount > 0)){
//			logger.warn("minor tick count cannot be less than 0, put default to 1");
//			minorTickCount = 1;
//		}

		scale.setMinorTickCount(minorTickCount);
		scale.setTickRadius(0.88);
		scale.setTickLabelOffset(0.15);
		//set tick label style
		Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
		scale.setTickLabelFont(tickLabelsFont);
		scale.setTickLabelPaint(labelsTickStyle.getColor());
		plot.addScale(0, scale);

		plot.addPointer(new DialPointer.Pin());

		DialCap cap = new DialCap();
		plot.setCap(cap);

		// sets intervals
		for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
			KpiInterval interval = (KpiInterval) iterator.next();
			StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), 
					interval.getColor()); 
			range.setInnerRadius(0.52);
			range.setOuterRadius(0.55);
			plot.addLayer(range);

		}

		GradientPaint gp = new GradientPaint(new Point(), 
				new Color(255, 255, 255), new Point(), 
				new Color(170, 170, 220));
		DialBackground db = new DialBackground(gp);
		db.setGradientPaintTransformer(new StandardGradientPaintTransformer(
				GradientPaintTransformType.VERTICAL));
		plot.setBackground(db);

		plot.removePointer(0);
		DialPointer.Pointer p = new DialPointer.Pointer();
		p.setFillPaint(Color.yellow);
		plot.addPointer(p);

		logger.debug("OUT");
		JFreeChart chart=new JFreeChart(name, plot);

		TextTitle title = setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}

		chart.setBackgroundPaint(color);
		return chart;
	}