Found this in my code hairball. YMMV...

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

import javax.imageio.ImageIO;

import com.representqueens.spark.BarGraph;
import com.representqueens.spark.LineGraph;
import com.representqueens.spark.SizeParams;

import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSData;

public class AVSparklineUtility {

        public static NSData smallBar(NSArray values) {
                return graph(40, 15, values, false);
        }
        public static NSData largeBar(NSArray values) {
                return graph(320, 120, values, false);
        }
        public static NSData smallLine(NSArray values) {
                return graph(40, 15, values, true);
        }
        public static NSData largeLine(NSArray values) {
                return graph(320, 120, values, true);
        }

private static NSData graph(int width, int height, NSArray integerArray, boolean isLine) {
                SizeParams params;
                BufferedImage i;
                Enumeration e;
                Vector<Integer> vector;
                Integer[] values;
                ByteArrayOutputStream baos;
                
                params = new SizeParams(width, height, 1);
                vector = new Vector<Integer>();
                if (integerArray.count() > 0) {
                        e = integerArray.objectEnumerator();
                        while (e.hasMoreElements()) {
                                vector.add(new Integer((Integer) 
e.nextElement()));
                        }
                }
                values = ((Integer[]) vector.toArray(new 
Integer[vector.size()]));
                
                if (isLine) {
                        i = LineGraph.createGraph(values, params, 
Color.blue.darker());
                }
                else {
i = BarGraph.createGraph(values, params, Color.blue.brighter(), Color.blue.darker(), Color.magenta);
                }
                baos = new ByteArrayOutputStream();
                
                try {
                        ImageIO.write(i, "png", baos);
                        return new NSData(baos.toByteArray());
                } catch (IOException ex) {
                        // TODO Auto-generated catch block
                        ex.printStackTrace();
                        return null;
                }
        }
}


On Jun 16, 2008, at 3:11 PM, Alex Cone wrote:

Anyone have a suggestion for something simple to drop into a WO
application to display sparklines?

Sparkline - Wikipedia, the free encyclopedia

__alex cone
   ceo  codefab  inc
   212 465-8484 x101
   [EMAIL PROTECTED]
   http://www.codefab.com


If you are not living on the edge, you are taking up too much space.

--
Josh Paul
[EMAIL PROTECTED]

twitter: joshpaul
linkedin: joshpaul


NOTICE: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to