Dashboard Home

Create Thermometer Chart | jfreechart | Dashboard Thermometer

Create Thermometer Chart | jfreechart | Dashboard Thermometer

To create this chart, your SQL should return only one column and one row

 

select sum(quantity_sold)   as qty_sold

from [detail_data$]

where fiscal_year =         2001

and country_region like         'Americas'      

 

When you first create the thermometer, it appears as below

 

 

You can add the following javascript code to enhance the look and feel

 

 

 

Here is the complete java script (beanshell) code

 

import org.jfree.chart.plot.ThermometerPlot;

import org.jfree.chart.JFreeChart;

import javax.imageio.ImageIO;

import java.awt.Toolkit;

import java.awt.Color;

import java.awt.image.BufferedImage;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.event.KeyEvent;

import java.io.File;

import java.io.IOException;

import java.net.URL;

ThermometerPlot plot = (ThermometerPlot)chart.getPlot();

//           plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

          plot.setThermometerStroke(new BasicStroke(2.0f));

          plot.setThermometerPaint(Color.lightGray);

          plot.setUnits(ThermometerPlot.UNITS_NONE);

        plot.setRange(50000.0,200000.0);

      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,w,h, new Color(102,0,102)));

//You can change the mercury color below

      plot.setMercuryPaint(new GradientPaint(0,0,Color.blue,w,h, new Color(102,0,102)));

      plot.setValuePaint(Color.black); //Change the color of the number inside the bulb

    plot.setThermometerPaint(Color.ORANGE); //Change the outside paint of the thermometer

 

/*

You can create ranges for the thermometer, you can add more ranges by just duplicating the following line and

incrementing the number

*/

plot.setSubrange(0, 0.0, 80000.0);

    plot.setSubrange(1, 80000.1, 120000.0);

    plot.setSubrange(2, 120000.1, 200000.0);

   

    plot.setSubrangePaint(2, Color.BLUE);

    plot.setSubrangePaint(1, Color.ORANGE);

    plot.setSubrangePaint(0, Color.RED);