Package net.sf.jasperreports.charts

Examples of net.sf.jasperreports.charts.JRMeterPlot


  /**
   *
   */
  protected JFreeChart createMeterChart() throws JRException
  {
    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // Start by creating the plot that will hold the meter
    MeterPlot chartPlot = new MeterPlot((ValueDataset)getDataset());

    // Set the shape
    MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.PIE : jrPlot.getShapeValue();
    switch (shape)
    {
      case CHORD :
        chartPlot.setDialShape(DialShape.CHORD);
        break;
      case CIRCLE :
        chartPlot.setDialShape(DialShape.CIRCLE);
        break;
      case PIE :
      default :
        chartPlot.setDialShape(DialShape.PIE);
    }

    // Set the meter's range
    chartPlot.setRange(convertRange(jrPlot.getDataRange()));

    // Set the size of the meter
    int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger().intValue();
    chartPlot.setMeterAngle(meterAngle);

    // Set the units - this is just a string that will be shown next to the
    // value
    String units = jrPlot.getUnits();
    if (units != null && units.length() > 0)
    {
      chartPlot.setUnits(units);
    }

    // Set the font used for tick labels
    if(jrPlot.getTickLabelFont() != null)
    {
      chartPlot.setTickLabelFont(JRFontUtil.getAwtFont(jrPlot.getTickLabelFont(), getLocale()));
    }
   
    // Set the spacing between ticks.  I hate the name "tickSize" since to me it
    // implies I am changing the size of the tick, not the spacing between them.
    double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble().doubleValue();
    chartPlot.setTickSize(tickInterval);

    // Set all the colors we support
    Color color = jrPlot.getMeterBackgroundColor();
    if (color != null)
    {
      chartPlot.setDialBackgroundPaint(color);
    }

    color = jrPlot.getNeedleColor();
    if (color != null)
    {
      chartPlot.setNeedlePaint(color);
    }

    // Set how the value is displayed.
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null)
    {
      if (display.getColor() != null)
      {
        chartPlot.setValuePaint(display.getColor());
      }

      if (display.getMask() != null)
      {
        chartPlot.setTickLabelFormat(new DecimalFormat(display.getMask()));
      }
      if (display.getFont() != null)
      {
        chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont(), getLocale()));
      }

    }

    color = jrPlot.getTickColor();
    if (color != null)
    {
      chartPlot.setTickPaint(color);
    }

    // Now define all of the intervals, setting their range and color
    List intervals = jrPlot.getIntervals();
    if (intervals != null)
    {
      Iterator iter = intervals.iterator();
      while (iter.hasNext())
      {
View Full Code Here


   *
   */
  protected JFreeChart createDialChart() throws JRException
  {

    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    dialPlot.setDataset((ValueDataset)getDataset());
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(jrPlot.getBackcolor());
    dialPlot.setBackground(db);
    Range range = convertRange(jrPlot.getDataRange());
    StandardDialScale scale =
      new StandardDialScale(
        range.getLowerBound(),
        range.getUpperBound(),
        225,
        -270,
        (range.getUpperBound() - range.getLowerBound())/6,
        15
        );
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    if(jrPlot.getTickLabelFont() != null)
    {
      scale.setTickLabelFont(JRFontUtil.getAwtFont(jrPlot.getTickLabelFont(), getLocale()));
    }
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.3f));
    scale.setMajorTickPaint(jrPlot.getTickColor());
    scale.setMinorTickPaint(jrPlot.getTickColor());

    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);

    dialPlot.addScale(0, scale);
    List intervals = jrPlot.getIntervals();
    if (intervals != null && intervals.size() > 0)
    {
      int size = Math.min(3, intervals.size());
      int colorStep = 0;
      if(size > 0)
      {
        colorStep = 255 / size;
      }
      for(int i = 0; i < size; i++)
      {
        JRMeterInterval interval = (JRMeterInterval)intervals.get(i);
        Range intervalRange = convertRange(interval.getDataRange());

        Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0);
       
        StandardDialRange dialRange =
          new StandardDialRange(
            intervalRange.getLowerBound(),
            intervalRange.getUpperBound(),
            interval.getBackgroundColor() == null
              ? color
              : interval.getBackgroundColor()
            );
        dialRange.setInnerRadius(0.41);
        dialRange.setOuterRadius(0.41);
        dialPlot.addLayer(dialRange);
      }
    }

    JRValueDisplay display = jrPlot.getValueDisplay();
    String displayVisibility = display != null && getChart().hasProperties()
      ? getChart().getPropertiesMap().getProperty(PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false";
    if(Boolean.valueOf(displayVisibility).booleanValue())
    {
      DialValueIndicator dvi = new DialValueIndicator(0);
      dvi.setBackgroundPaint(TRANSPARENT_PAINT);
//      dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
      dvi.setOutlinePaint(TRANSPARENT_PAINT);
      dvi.setPaint(Color.WHITE);

      String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
      if(pattern != null)
      {
        dvi.setNumberFormat( new DecimalFormat(pattern));
      }
      dvi.setRadius(0.15);
      dvi.setValueAnchor(RectangleAnchor.CENTER);
      dvi.setTextAnchor(TextAnchor.CENTER);
      //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale)));
      dialPlot.addLayer(dvi);
    }
    String label = getChart().hasProperties() ?
        getChart().getPropertiesMap().getProperty(PROPERTY_DIAL_LABEL) : null;
   
    if(label != null)
    {
      JRFont displayFont = jrPlot.getValueDisplay().getFont();
     
      String[] textLines = label.split("\\n");
      for(int i = 0; i < textLines.length; i++)
      {
        DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
        if(displayFont != null)
        {
          dialAnnotation.setFont(JRFontUtil.getAwtFont(displayFont, getLocale()));
        }
        dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor());
        dialAnnotation.setRadius(Math.sin(Math.PI/4.0) + i/10.0);
        dialAnnotation.setAnchor(TextAnchor.CENTER);
        dialPlot.addLayer(dialAnnotation);
      }
    }
View Full Code Here

   * @param evaluation current expression evaluation phase
   * @throws JRException
  */
  protected JFreeChart createMeterChart() throws JRException
  {
    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // Start by creating the plot that will hold the meter
    MeterPlot chartPlot = new MeterPlot((ValueDataset)getDataset());

    // Set the shape
    MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.PIE : jrPlot.getShapeValue();
    if (shape == MeterShapeEnum.CHORD)
      chartPlot.setDialShape(DialShape.CHORD);
    else if (shape == MeterShapeEnum.CIRCLE)
      chartPlot.setDialShape(DialShape.CIRCLE);
    else if (shape == MeterShapeEnum.DIAL)
      return createDialChart();
    else
      chartPlot.setDialShape(DialShape.PIE);

    // Set the meter's range
    chartPlot.setRange(convertRange(jrPlot.getDataRange()));

    // Set the size of the meter
    int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger().intValue();
    chartPlot.setMeterAngle(meterAngle);

    // Set the units - this is just a string that will be shown next to the
    // value
    String units = jrPlot.getUnits();
    if (units != null && units.length() > 0)
      chartPlot.setUnits(units);

    // Set the spacing between ticks.  I hate the name "tickSize" since to me it
    // implies I am changing the size of the tick, not the spacing between them.
    double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble().doubleValue();
    chartPlot.setTickSize(tickInterval);

    // Set all the colors we support
    Color color = jrPlot.getMeterBackgroundColor();
    if (color != null)
      chartPlot.setDialBackgroundPaint(color);

    color = jrPlot.getNeedleColor();
    if (color != null)
      chartPlot.setNeedlePaint(color);

    JRBaseFont font = new JRBaseFont();
    JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getTickLabelFont(), font);
    JRFontUtil.copyNonNullOwnProperties(jrPlot.getTickLabelFont(), font);
    font = new JRBaseFont(getChart(), font);
    chartPlot.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale()));

    // Set how the value is displayed.
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null)
    {
      if (display.getColor() != null)
      {
        chartPlot.setValuePaint(display.getColor());
      }

      if (display.getMask() != null)
      {
        chartPlot.setTickLabelFormat(new DecimalFormat(display.getMask()));
      }
     
      font = new JRBaseFont();
      JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getDisplayFont(), font);
      JRFontUtil.copyNonNullOwnProperties(jrPlot.getValueDisplay().getFont(), font);
      font = new JRBaseFont(getChart(), font);
      chartPlot.setValueFont(JRFontUtil.getAwtFont(font, getLocale()));

    }

    color = jrPlot.getTickColor();
    if (color != null)
      chartPlot.setTickPaint(color);

    // Now define all of the intervals, setting their range and color
    List intervals = jrPlot.getIntervals();
    if (intervals != null)
    {
      Iterator iter = intervals.iterator();
      while (iter.hasNext())
      {
View Full Code Here

   *
   */
  protected JFreeChart createDialChart() throws JRException
  {

    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    dialPlot.setDataset((ValueDataset)getDataset());
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(jrPlot.getBackcolor());
    dialPlot.setBackground(db);
    Range range = convertRange(jrPlot.getDataRange());
    //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));

    StandardDialScale scale =
      new StandardDialScale(
        range.getLowerBound(),
        range.getUpperBound(),
        225,
        -270,
        (range.getUpperBound() - range.getLowerBound())/6,
        15
        );
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    JRBaseFont font = new JRBaseFont();
    JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getTickLabelFont(), font);
    JRFontUtil.copyNonNullOwnProperties(jrPlot.getTickLabelFont(), font);
    font = new JRBaseFont(getChart(), font);
    scale.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale()));
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.3f));
    scale.setMajorTickPaint(jrPlot.getTickColor());
    scale.setMinorTickPaint(jrPlot.getTickColor());

    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);

    dialPlot.addScale(0, scale);
    List intervals = jrPlot.getIntervals();
    if (intervals != null && intervals.size() > 0)
    {
      int size = Math.min(3, intervals.size());
      int colorStep = 0;
      if(size > 0)
        colorStep = 255 / size;
     
      for(int i = 0; i < size; i++)
      {
        JRMeterInterval interval = (JRMeterInterval)intervals.get(i);
        Range intervalRange = convertRange(interval.getDataRange());

        Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0);
       
        StandardDialRange dialRange =
          new StandardDialRange(
            intervalRange.getLowerBound(),
            intervalRange.getUpperBound(),
            interval.getBackgroundColor() == null
              ? color
              : interval.getBackgroundColor()
            );
        dialRange.setInnerRadius(0.41);
        dialRange.setOuterRadius(0.41);
        dialPlot.addLayer(dialRange);
      }
    }

    JRValueDisplay display = jrPlot.getValueDisplay();
    String displayVisibility = display != null && getChart().hasProperties() ?
      getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false";

    if(Boolean.parseBoolean(displayVisibility))
    {
      DialValueIndicator dvi = new DialValueIndicator(0);
      dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
//      dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
      dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
      dvi.setPaint(Color.WHITE);

      String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
      if(pattern != null)
        dvi.setNumberFormat( new DecimalFormat(pattern));
      dvi.setRadius(0.15);
      dvi.setValueAnchor(RectangleAnchor.CENTER);
      dvi.setTextAnchor(TextAnchor.CENTER);
      //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale)));
      dialPlot.addLayer(dvi);
    }
    String label = getChart().hasProperties() ?
        getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null;
   
    if(label != null)
    {
      JRFont displayFont = new JRBaseFont();
      JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getDisplayFont(), displayFont);
      JRFontUtil.copyNonNullOwnProperties(jrPlot.getValueDisplay().getFont(), displayFont);
      displayFont = new JRBaseFont(getChart(), displayFont);
      Font themeDisplayFont = JRFontUtil.getAwtFont(displayFont, getLocale());
     
      String[] textLines = label.split("\\n");
      for(int i = 0; i < textLines.length; i++)
      {
        DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
        dialAnnotation.setFont(themeDisplayFont);
        dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor());
        dialAnnotation.setRadius(Math.sin(Math.PI/4.0) + i/10.0);
        dialAnnotation.setAnchor(TextAnchor.CENTER);
        dialPlot.addLayer(dialAnnotation);
      }
    }
View Full Code Here

   */
  protected JFreeChart createMeterChart() throws JRException
  {
    // Start by creating the plot that will hold the meter
    MeterPlot chartPlot = new MeterPlot((ValueDataset)getDataset());
    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // Set the shape
    MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.DIAL : jrPlot.getShapeValue();
   
    switch(shape)
    {
      case CHORD:
        chartPlot.setDialShape(DialShape.CHORD);
        break;
      case PIE:
        chartPlot.setDialShape(DialShape.PIE);
        break;
      case CIRCLE:
        chartPlot.setDialShape(DialShape.CIRCLE);
        break;
      case DIAL:
      default:
        return createDialChart();
    }

    chartPlot.setDialOutlinePaint(Color.BLACK);
    int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger().intValue();
    // Set the size of the meter
    chartPlot.setMeterAngle(meterAngle);

    // Set the spacing between ticks.  I hate the name "tickSize" since to me it
    // implies I am changing the size of the tick, not the spacing between them.
    double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble().doubleValue();
    chartPlot.setTickSize(tickInterval);
   
    JRFont tickLabelFont = jrPlot.getTickLabelFont();
    Integer defaultBaseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
    Font themeTickLabelFont = getFont((JRFont)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize);
    chartPlot.setTickLabelFont(themeTickLabelFont);
   
    Color tickColor = jrPlot.getTickColor() == null ? Color.BLACK : jrPlot.getTickColor();
    chartPlot.setTickPaint(tickColor);
    int dialUnitScale = 1;
    Range range = convertRange(jrPlot.getDataRange());
    if(range != null)
    {
      // Set the meter's range
      chartPlot.setRange(range);
      double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));
      dialUnitScale = ChartThemesUtilities.getScale(bound);
      if((range.getLowerBound() == (int)range.getLowerBound() &&
          range.getUpperBound() == (int)range.getUpperBound() &&
          tickInterval == (int)tickInterval) ||
          dialUnitScale > 1
          )
      {
        chartPlot.setTickLabelFormat(new DecimalFormat("#,##0"));
      }
      else if(dialUnitScale == 1)
      {
        chartPlot.setTickLabelFormat(new DecimalFormat("#,##0.0"));
      }
      else if(dialUnitScale <= 0)
      {
        chartPlot.setTickLabelFormat(new DecimalFormat("#,##0.00"));
      }
    }
    chartPlot.setTickLabelsVisible(true);

    // Set all the colors we support
    Paint backgroundPaint = jrPlot.getOwnBackcolor() == null ? ChartThemesConstants.TRANSPARENT_PAINT : jrPlot.getOwnBackcolor();
    chartPlot.setBackgroundPaint(backgroundPaint);

    GradientPaint gp =
      new GradientPaint(
        new Point(), Color.LIGHT_GRAY,
        new Point(), Color.BLACK,
        false
        );
   
    if(jrPlot.getMeterBackgroundColor() != null)
    {
      chartPlot.setDialBackgroundPaint(jrPlot.getMeterBackgroundColor());
    }
    else
    {
      chartPlot.setDialBackgroundPaint(gp);
    }
    //chartPlot.setForegroundAlpha(1f);
    Paint needlePaint = jrPlot.getNeedleColor() == null ? new Color(191, 48, 0) : jrPlot.getNeedleColor();
    chartPlot.setNeedlePaint(needlePaint);

    JRValueDisplay display = jrPlot.getValueDisplay();
    if(display != null)
    {
      Color valueColor = display.getColor() == null ? Color.BLACK : display.getColor();
      chartPlot.setValuePaint(valueColor);
      String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
      if(pattern != null)
        chartPlot.setTickLabelFormat( new DecimalFormat(pattern));
      JRFont displayFont = display.getFont();
      Font themeDisplayFont = getFont((JRFont)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize);
 
      if (themeDisplayFont != null)
      {
        chartPlot.setValueFont(themeDisplayFont);
      }
    }
    String label = getChart().hasProperties() ?
        getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null;
   
    if(label != null)
    {
      if(dialUnitScale < 0)
        label = new MessageFormat(label).format(new Object[]{String.valueOf(Math.pow(10, dialUnitScale))});
      else if(dialUnitScale < 3)
        label = new MessageFormat(label).format(new Object[]{"1"});
      else
        label = new MessageFormat(label).format(new Object[]{String.valueOf((int)Math.pow(10, dialUnitScale-2))});
   
    }
   
    // Set the units - this is just a string that will be shown next to the
    // value
    String units = jrPlot.getUnits() == null ? label : jrPlot.getUnits();
    if (units != null && units.length() > 0)
      chartPlot.setUnits(units);

    chartPlot.setTickPaint(Color.BLACK);

    // Now define all of the intervals, setting their range and color
    List intervals = jrPlot.getIntervals();
    if (intervals != null  && intervals.size() > 0)
    {
      int size = Math.min(3, intervals.size());
     
      int colorStep = 0;
View Full Code Here

   *
   */
  protected JFreeChart createDialChart() throws JRException
  {

    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    if(getDataset() != null)
    {
      dialPlot.setDataset((ValueDataset)getDataset());
    }
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setForegroundPaint(Color.BLACK);
    dialFrame.setBackgroundPaint(Color.BLACK);
    dialFrame.setStroke(new BasicStroke(1f));
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT);
    dialPlot.setBackground(db);
    ScaledDialScale scale = null;
    int dialUnitScale = 1;
    Range range = convertRange(jrPlot.getDataRange());
    if(range != null)
    {
      double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));
      dialUnitScale = ChartThemesUtilities.getScale(bound);
 
      double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale);
      double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale);
 
      scale =
        new ScaledDialScale(
          lowerBound,
          upperBound,
          210,
          -240,
          (upperBound - lowerBound)/6,
          1
          );
      if((lowerBound == (int)lowerBound &&
          upperBound == (int)upperBound &&
          scale.getMajorTickIncrement() == (int)scale.getMajorTickIncrement()) ||
          dialUnitScale > 1
          )
      {
        scale.setTickLabelFormatter(new DecimalFormat("#,##0"));
      }
      else if(dialUnitScale == 1)
      {

        scale.setTickLabelFormatter(new DecimalFormat("#,##0.0"));
      }
      else if(dialUnitScale <= 0)
      {
        scale.setTickLabelFormatter(new DecimalFormat("#,##0.00"));
      }
    }
    else
    {
      scale = new ScaledDialScale();
    }
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    JRFont tickLabelFont = jrPlot.getTickLabelFont();
    Integer defaultBaseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
    Font themeTickLabelFont = getFont((JRFont)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize);
    scale.setTickLabelFont(themeTickLabelFont);
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.7f));
    scale.setMajorTickPaint(Color.BLACK);
    scale.setMinorTickPaint(Color.BLACK);
    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);
    dialPlot.addScale(0, scale);
   
   
    List intervals = jrPlot.getIntervals();
    if (intervals != null && intervals.size() > 0)
    {
      int size = Math.min(3, intervals.size());
     
      int colorStep = 0;
      if(size > 3)
        colorStep = 255 / (size - 3);
     
      for(int i = 0; i < size; i++)
      {
        JRMeterInterval interval = (JRMeterInterval)intervals.get(i);
        Range intervalRange = convertRange(interval.getDataRange());
        double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale);
        double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale);

        Color color = i < 3
          ? (Color)ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i)
          : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0);
          ScaledDialRange dialRange =
            new ScaledDialRange(
              intervalLowerBound,
              intervalUpperBound,
              interval.getBackgroundColor() == null
                ? color
                : interval.getBackgroundColor(),
              15f
              );
        dialRange.setInnerRadius(0.5);
        dialRange.setOuterRadius(0.5);
        dialPlot.addLayer(dialRange);
      }
     
    }
    JRValueDisplay display = jrPlot.getValueDisplay();

    String displayVisibility = display != null && getChart().hasProperties() ?
        getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false";

    if(Boolean.valueOf(displayVisibility).booleanValue())
    {
      ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale);
      dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
//      dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
      dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
      dvi.setPaint(Color.WHITE);

      String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
      if(pattern != null)
        dvi.setNumberFormat( new DecimalFormat(pattern));
      dvi.setRadius(0.15);
      dvi.setValueAnchor(RectangleAnchor.CENTER);
      dvi.setTextAnchor(TextAnchor.CENTER);
      //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale)));
      dialPlot.addLayer(dvi);
    }
   
    String label = getChart().hasProperties() ?
        getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null;

    if(label != null)
    {
      if(dialUnitScale < 0)
        label = new MessageFormat(label).format(new Object[]{String.valueOf(Math.pow(10, dialUnitScale))});
      else if(dialUnitScale < 3)
        label = new MessageFormat(label).format(new Object[]{"1"});
      else
        label = new MessageFormat(label).format(new Object[]{String.valueOf((int)Math.pow(10, dialUnitScale-2))});

      JRFont displayFont = jrPlot.getValueDisplay().getFont();
      Font themeDisplayFont = getFont((JRFont)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize);
     
      String[] textLines = label.split("\\n");
      for(int i = 0; i < textLines.length; i++)
      {
View Full Code Here

    writeChart(chart);
    writeValueDataset((JRValueDataset) chart.getDataset());

    // write plot
    JRMeterPlot plot = (JRMeterPlot) chart.getPlot();
    writer.startElement(JRMeterPlotFactory.ELEMENT_meterPlot);
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_shape, plot.getShapeValue());
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_angle, plot.getMeterAngleInteger());
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_units, plot.getUnits());
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_tickInterval, plot.getTickIntervalDouble());
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_meterColor, plot.getMeterBackgroundColor());
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_needleColor, plot.getNeedleColor());
    writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_tickColor, plot.getTickColor());
   
    writePlot(chart.getPlot());
    if (plot.getTickLabelFont() != null)
    {
      writer.startElement(JRXmlConstants.ELEMENT_tickLabelFont);
      writeFont(plot.getTickLabelFont());
      writer.closeElement();
    }
    writeValueDisplay(plot.getValueDisplay());
    writeDataRange(plot.getDataRange());

    List intervals = plot.getIntervals();
    if (intervals != null)
    {
      Iterator iter = intervals.iterator();
      while (iter.hasNext())
      {
View Full Code Here

    if(chart != null)
    {
      write( "JRDesignChart " + chartName + " = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_METER);\n");
      writeChart( chart, chartName);
      writeValueDataset( (JRValueDataset) chart.getDataset(), chartName, "ValueDataset");
      JRMeterPlot plot = (JRMeterPlot) chart.getPlot();
      if(plot != null)
      {
        String plotName = chartName + "MeterPlot";
       
        write( "JRDesignMeterPlot " + plotName + " = (JRDesignMeterPlot)" + chartName + ".getPlot();\n");
        write( plotName + ".setShape({0});\n", plot.getShapeValue());
        write( plotName + ".setMeterAngle(Integer.valueOf({0, number, #}));\n", plot.getMeterAngleInteger());
       
        write( plotName + ".setUnits(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(plot.getUnits()));
        write( plotName + ".setTickInterval({0});\n", plot.getTickIntervalDouble());
        write( plotName + ".setMeterBackgroundColor({0});\n", plot.getMeterBackgroundColor());
        write( plotName + ".setNeedleColor({0});\n", plot.getNeedleColor());
        write( plotName + ".setTickColor({0});\n", plot.getTickColor());
       
        writePlot( plot, plotName);
        if (plot.getTickLabelFont() != null)
        {
          writeFont( plot.getTickLabelFont(), plotName + ".getTickLabelFont()");
          flush();
        }
        writeValueDisplay( plot.getValueDisplay(), plotName);
        writeDataRange( plot.getDataRange(), plotName, "DataRange");

        List intervals = plot.getIntervals();
        if (intervals != null && intervals.size() > 0)
        {
          for(int i = 0; i < intervals.size(); i++)
          {
            JRMeterInterval meterInterval = (JRMeterInterval) intervals.get(i);
View Full Code Here

   */
  public JRBaseMeterPlot(JRChartPlot plot, JRChart chart)
  {
    super(plot, chart);
   
    JRMeterPlot meterPlot = plot instanceof JRMeterPlot ? (JRMeterPlot)plot : null;
    if (meterPlot == null)
    {
      valueDisplay = new JRBaseValueDisplay(null, chart);
      tickLabelFont = new JRBaseFont(chart, null);
    }
    else
    {
      valueDisplay = new JRBaseValueDisplay(meterPlot.getValueDisplay(), chart);
      tickLabelFont = new JRBaseFont(chart, meterPlot.getTickLabelFont());
    }
  }
View Full Code Here

  */
  protected JFreeChart createMeterChart() throws JRException
  {
    // Start by creating the plot that will hold the meter
    MeterPlot chartPlot = new MeterPlot((ValueDataset)getDataset());
    JRMeterPlot jrPlot = (JRMeterPlot)getPlot();

    // Set the shape
    MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.PIE : jrPlot.getShapeValue();
   
    switch(shape)
    {
      case CHORD:
        chartPlot.setDialShape(DialShape.CHORD);
        break;
      case CIRCLE:
        chartPlot.setDialShape(DialShape.CIRCLE);
        break;
      case DIAL:
        return createDialChart();
      case PIE:
      default:
        chartPlot.setDialShape(DialShape.PIE);
    }

    // Set the meter's range
    chartPlot.setRange(convertRange(jrPlot.getDataRange()));

    // Set the size of the meter
    int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger().intValue();
    chartPlot.setMeterAngle(meterAngle);

    // Set the units - this is just a string that will be shown next to the
    // value
    String units = jrPlot.getUnits();
    if (units != null && units.length() > 0)
      chartPlot.setUnits(units);

    // Set the spacing between ticks.  I hate the name "tickSize" since to me it
    // implies I am changing the size of the tick, not the spacing between them.
    double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble().doubleValue();
    chartPlot.setTickSize(tickInterval);

    // Set all the colors we support
    Color color = jrPlot.getMeterBackgroundColor();
    if (color != null)
      chartPlot.setDialBackgroundPaint(color);

    color = jrPlot.getNeedleColor();
    if (color != null)
      chartPlot.setNeedlePaint(color);

    JRFont tickLabelFont = jrPlot.getTickLabelFont();
    Integer defaultBaseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
    Font themeTickLabelFont = getFont((JRFont)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize);
    chartPlot.setTickLabelFont(themeTickLabelFont);
   
    JRValueDisplay display = jrPlot.getValueDisplay();
    JRFont displayFont = display.getFont();
    Font themeDisplayFont = getFont((JRFont)getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize);
    // Set how the value is displayed.
    if (display != null)
    {
      if (display.getColor() != null)
      {
        chartPlot.setValuePaint(display.getColor());
      }

      if (display.getMask() != null)
      {
        chartPlot.setTickLabelFormat(new DecimalFormat(display.getMask()));
      }
      if (display.getFont() != null)
      {
        chartPlot.setValueFont(themeDisplayFont);
      }

    }

    color = jrPlot.getTickColor();
    if (color != null)
      chartPlot.setTickPaint(color);

    // Now define all of the intervals, setting their range and color
    List intervals = jrPlot.getIntervals();
    if (intervals != null)
    {
      Iterator iter = intervals.iterator();
      while (iter.hasNext())
      {
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.charts.JRMeterPlot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.