Jump to content
We've recently updated our Privacy Statement, available here ×

Chart/Status Bar problem


vickirk

Recommended Posts

Hi,

I'm trying to create a status bar indicator using a chart.  What I want is to create is a horizontal bar with a value from 0 to 100.  I tried creating using a horizontal bar chart and turning off the labels/legend/ticks however the ticks remain and seem to ignore the setting.  I also thought I'd try a thermometer type chart but would need to get rid of the "bulb" and the oreientation field is ignored.

The bar needs to be the same height as a line of text.

Is there another way of doing it or is there any documentation on how to expand the charts available.

Thanks, Vic

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The attached class render something of similar of what you want (you can adjust it, it is just a proof of concept).

The class must be in the classpath (attached a jar with that class).

To use it, just add an image element and set the expression to:

gradientcomponent.GradientComponent.create(new Double(0.75))

new Double(0.75) can be replaced with your value. It bust be between 0 and 1.

Set the image so fill frame.
To improve the quality, you can set the image size:

gradientcomponent.GradientComponent.create(new Double(0.75), 543, 50)

 Have fun

Giulio

Code:
package gradientcomponent;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics2D;import java.awt.Shape;import java.awt.image.BufferedImage;/** * * @author gtoffoli */public class GradientComponent {    public static Color background = Color.WHITE;    public static BufferedImage create(Double value)    {        return create(value, 800, 50);    }    public static BufferedImage create(Double value, int imgWidth, int imgHeight)    {        BufferedImage buf = new BufferedImage(900, 50, BufferedImage.TYPE_INT_ARGB);        Graphics2D g = buf.createGraphics();        g.setColor(background);        g.fillRect(0, 0,imgWidth , imgHeight);        Shape oldClip = g.getClip();        g.clipRect(0, 0, (int)(imgWidth*value), imgHeight);        // Red to yellow...        GradientPaint gradient = new GradientPaint(0,0, Color.RED, imgWidth/2,0,Color.YELLOW);        g.setPaint(gradient);        g.fillRect(0,0,imgWidth/2,imgHeight);        // Yellow to green        gradient = new GradientPaint(imgWidth/2,0, Color.YELLOW, imgWidth,0,Color.GREEN);        g.setPaint(gradient);        g.fillRect(imgWidth/2,0,imgWidth,imgHeight);        g.setClip(oldClip);        g.setColor(Color.BLACK);        g.drawRect(0,0,imgWidth-1, imgHeight-1);        return buf;    }}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...