To draw  bar graph

hi i am doing a portal there i want show the selected row in a bar graph format. is there any format or third party tool so that i can icorporate for drawing graph. nor should i alter my servlets code for it.

hello vijay,
i got one code from google about the drawing of the graph. after seeing that code , i think it will not take the data automatically it should manually.
// BarChart.java
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
* Generic bar chart class with full selection set support.
* @author Melinda Green
public class BarChart extends JPanel {
* implemented by data objects to be charted.
public interface BarValue {
/** specifies the hight (data value) of this bar. */
public float getBarValue();
/** optional summary text suitable for tool-tip or other display.*/
public String getInfoText();
public final static int
SORT_NONE = 0,
SORT_ASCENDING = 1,
SORT_DESCENDING = 2;
public final static int
LINEAR_SCALE = 0,
LOG_SCALE = 1;
private static final int
CHART_LEFT_PAD = 50,
CHART_RIGHT_PAD = 25,
CHART_TOP_PAD = 50,
CHART_BOTTOM_PAD = 50,
CHART_MIN_DIM = 80,
MAX_TIC_LABELS = 10, // greatest number of axis tic labels
TIC_LENGTH = 6, // length of axis tic marks
MIN_BOX_WIDTH_FOR_SEPERATOR = 8; // looks crummy if too small
private final static String NO_VALUES_MSG = "No Bar Values Set";
private static final Color NORMAL_COLOR = Color.blue.darker();
private static final Color HIGHLIGHT_COLOR = Color.yellow;
private String xAxisLabel, yAxisLabel;
private int xScaleType, yScaleType; // log or linear
private SelectionSet selections;
private BarValue barValues[] = null;
private float highVal;
private int anchorSelectionIndex = 0; // base index for range selections
private final Rectangle tmpRect = new Rectangle(); // scratch space
* constructs a BarChart panel.
* @param xAxisLabel - String to draw on x axis - optional.
* @param yAxisLabel - String to draw on y axis - optional.
* @param logScale determines whether to draw x axis on log or linear scale.
* @param sel is an optional SelectionSet. the bar chart class always
* maintains a SelectionSet object which it updates on UI selections.
* callers may call getSelectionSet to monitor BarChart selections and
* to make selection changes which the BarChart will respond to. if
* a non-null SelectionSet parameter is provided here, the BarChart will
* listen to and modify the given one instead.
public BarChart(String xAxisLabel, String yAxisLabel,
int xAxisScaleType, int yAxisScaleType, SelectionSet sel)
this.xAxisLabel = xAxisLabel;
this.yAxisLabel = yAxisLabel;
this.selections = sel == null ? new SelectionSet(BarValue.class) : sel;
setScaleType(Axis.X_AXIS, xAxisScaleType);
setScaleType(Axis.Y_AXIS, yAxisScaleType);
setMinimumSize(new Dimension(
CHART_MIN_DIM + CHART_LEFT_PAD + CHART_RIGHT_PAD,
CHART_MIN_DIM + CHART_TOP_PAD + CHART_BOTTOM_PAD));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {           
int b = barAt(me.getPoint().x, me.getPoint().y);
if(b < 0) {
if(!me.isControlDown())
selections.clear(BarChart.this);
repaint();
return;
BarValue selectedBar = barValues;
selections.beginEditing(BarChart.this, false);
if(me.isShiftDown())
selectRange(b, anchorSelectionIndex);
else if(me.isControlDown())
selections.toggle(selectedBar, BarChart.this);
else
selections.setElements(selectedBar, BarChart.this);
if(!me.isShiftDown())
anchorSelectionIndex = b;
selections.endEditing(BarChart.this);
repaint();
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent me) {
selectRange(barAt(me.getPoint().x), anchorSelectionIndex);
repaint();
} // end constructor
public void setBarValues(BarValue barValues[], final int sortType) {
this.barValues = new BarValue[barValues.length];
System.arraycopy(barValues, 0, this.barValues, 0, barValues.length);
highVal = Float.MIN_VALUE;
for(int i=0; i<barValues.length; i++)
highVal = Math.max(highVal, barValues.getBarValue());
if (sortType != SORT_NONE) {
Arrays.sort(this.barValues, new Comparator() {
public int compare(Object a, Object b) {
float val1 = ((BarValue)a).getBarValue();
float val2 = ((BarValue)b).getBarValue();
if (sortType == SORT_ASCENDING) {
float tmp = val1;
val1 = val2;
val2 = tmp;
return val2 - val1 > 0 ? 1 : val2 == val1 ? 0 : -1; // NOTE: reverse numeric order
repaint();
} // end setBarValues
public void setScaleType(int axis, int type) {
if( ! (type == LOG_SCALE || type == LINEAR_SCALE))
throw new IllegalArgumentException("BarChart.setScaleType: bad scale type " + type);
if(axis == Axis.X_AXIS)
xScaleType = type;
else
yScaleType = type;
repaint();
* returns the selection set object being used.
* this is either the one provided to the constuctor,
* generated internally otherwise.
public SelectionSet getSelectionSet() {
return selections;
private void selectRange(int b1, int b2) {
if(b1 < 0 || b2 < 0)
return;
selections.clear(BarChart.this);
int range_start = Math.min(b1, b2);
int range_end = Math.max(b1, b2);
for(int i=range_start; i<=range_end; i++)
selections.addElement(barValues[i], BarChart.this);
private void computeBar(int barID, Rectangle rect) {
int chart_width = getWidth() - (CHART_LEFT_PAD+CHART_RIGHT_PAD);
int chart_height = getHeight() - (CHART_TOP_PAD+CHART_BOTTOM_PAD);
int chart_right = CHART_LEFT_PAD + chart_width;
int chart_bottom = CHART_TOP_PAD + chart_height;
rect.height = Math.round(barValues[barID].getBarValue() / highVal * chart_height);
rect.y = CHART_TOP_PAD + (chart_height - rect.height);
if (xScaleType==LINEAR_SCALE) {
rect.width = Math.round(chart_width / (float)barValues.length);
rect.x = CHART_LEFT_PAD + barID * rect.width;
else {
rect.x = 0;
if (barID > 0)
rect.x = Axis.plotValue(barID,
.5f, barValues.length, // value range
CHART_LEFT_PAD, getWidth()-CHART_RIGHT_PAD, // screen range
true, getHeight());
int next = Axis.plotValue(barID+1,
.5f, barValues.length, // value range
CHART_LEFT_PAD, getWidth()-CHART_RIGHT_PAD, // screen range
true, getHeight());
rect.width = next - rect.x;
rect.x += CHART_LEFT_PAD;
public void paint(Graphics g) {
super.paint(g);
Point center = new Point(getWidth()/2, getHeight()/2);
if(g instanceof Graphics2D)
center.x -= stringWidth(NO_VALUES_MSG, g) / 2;
if (barValues == null || barValues.length == 0) {
g.drawString(NO_VALUES_MSG, center.x, center.y);
return;
// draw the data boxes
int lastxend = 0;
int chart_width = getWidth() - (CHART_LEFT_PAD+CHART_RIGHT_PAD);
boolean drawBoxSeperators = chart_width / (float)barValues.length > MIN_BOX_WIDTH_FOR_SEPERATOR;
for(int i=0; i<barValues.length; i++) {
g.setColor(selections.contains(barValues[i]) ? HIGHLIGHT_COLOR : NORMAL_COLOR);
computeBar(i, tmpRect);
if(i == 0)
lastxend = tmpRect.x + tmpRect.width;
else {
if (tmpRect.x > lastxend) {
int diff = tmpRect.x - lastxend;
tmpRect.x = lastxend;
tmpRect.width += diff;
lastxend = tmpRect.x+tmpRect.width;
//System.out.println(tmpRect.x + "," + tmpRect.y + " w=" + tmpRect.width + " h=" + tmpRect.height + " lastxend=" + lastxend);
g.fillRect(tmpRect.x, tmpRect.y, tmpRect.width, tmpRect.height);
g.setColor(Color.gray);
if(drawBoxSeperators && i > 0) // draw a line between each box pair
g.drawLine(tmpRect.x, tmpRect.y, tmpRect.x, tmpRect.y+tmpRect.height);
// draw the axes
g.setColor(Color.black);
Axis.drawAxis(Axis.X_AXIS, MAX_TIC_LABELS, TIC_LENGTH,
.5f, barValues.length, // value range
CHART_LEFT_PAD, getWidth()-CHART_RIGHT_PAD, // screen range
CHART_BOTTOM_PAD, xScaleType==LOG_SCALE, getHeight(), g);
Axis.drawAxis(Axis.Y_AXIS, MAX_TIC_LABELS, TIC_LENGTH,
0, highVal, // value range
CHART_BOTTOM_PAD, getHeight()-CHART_TOP_PAD, // screen range
CHART_LEFT_PAD, yScaleType==LOG_SCALE, getHeight(), g);
Font bold = g.getFont().deriveFont(Font.BOLD);
g.setFont(bold);
if (xAxisLabel != null) {
g.drawString(xAxisLabel, getWidth()-stringWidth(xAxisLabel, g)-20, getHeight()-10);
if (yAxisLabel != null) {
g.drawString(yAxisLabel, CHART_LEFT_PAD-40, 25);
} // end paint
private int barAt(int x, int y) {
if(barValues == null)
return -1;
for(int i=0; i<barValues.length; i++) {
computeBar(i, tmpRect);
if(rectContainsPoint(tmpRect, x, y))
return i;
return -1;
private static boolean rectContainsPoint(Rectangle rect, int x, int y) {
return
rect.x <= x && x <= rect.x+rect.width &&
rect.y <= y && y <= rect.y+rect.height;
private int barAt(int x) {
if(barValues == null)
return -1;
for(int i=0; i<barValues.length; i++) {
computeBar(i, tmpRect);
if(tmpRect.x <= x && x <= tmpRect.x+tmpRect.width)
return i;
return -1;
public static int stringWidth(String str, Graphics g) {
if(g instanceof Graphics2D)
return (int)(g.getFont().getStringBounds(str, ((Graphics2D)g).getFontRenderContext()).getWidth()+.5);
else
return g.getFontMetrics().stringWidth(str);
private static class TestDatum implements BarChart.BarValue {
private int id;
private int dataValue;
public TestDatum(int id, int value) {
this.id = id;
this.dataValue = value;
public int getID() { return id; }
public int getDataValue() { return dataValue; }
public float getBarValue() { return getDataValue(); }
public String getInfoText() { return "id # " + id + ", " + dataValue + " value"; }
* example data. unsorted but will have BarChart perform the sorting.
private final static TestDatum testSamples[] = new TestDatum[] {
new TestDatum(12, 2020),
new TestDatum(88, 2300),
new TestDatum(43, 3001),
new TestDatum(81, 2405),
new TestDatum(10, 2069),
new TestDatum( 2, 2054),
new TestDatum(74, 2339),
new TestDatum(56, 2020),
new TestDatum(57, 2021),
new TestDatum(58, 2023),
new TestDatum(59, 2022),
new TestDatum( 4, 4700),
new TestDatum(98, 3100),
new TestDatum(90, 3454),
new TestDatum(33, 2560),
new TestDatum(99, 2299),
new TestDatum(78, 2020),
new TestDatum(65, 2020),
public static void main(String args[]) {
SelectionSet selections = new SelectionSet(TestDatum.class);
selections.addSelectionSetListener(new SelectionSetListener() {
public void selectionSetChanged(SelectionSet set, Object source) {
System.out.println("main: " + set.getNumElements() + " selected ");
BarChart chart = new BarChart("Number of Samples", "Data Value",
BarChart.LOG_SCALE, BarChart.LINEAR_SCALE, selections);
chart.setBarValues(testSamples, BarChart.SORT_DESCENDING);
JFrame frame = new JFrame("Bar Chart Test");
frame.getContentPane().add(chart);
frame.setSize(new Dimension(500, 500));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
} // end class BarChart

Similar Messages

  • How do I plot bar graph using MStudio.NE​T for VB

    I can not find the FillToBase property in waveformplot object using MStudio 7.0 for VB.NET. How can I plot the bar graph like that in Mstudio 6.0.

    The Measurement Studio .NET WaveformPlot does not currently have an equivalent for CWPlot's FillToBase property. In the meantime, though, you can use the WaveformPlot's custom drawing services to emulate this functionality. For example, if you dropped a new WaveformGraph on a form, you could copy and paste the following code to draw bar graphs on the WaveformPlot:
    Private Sub OnBeforeDrawPlot(ByVal sender As Object, ByVal e As BeforeDrawXYPlotEventArgs) Handles WaveformPlot1.BeforeDraw
    DrawBarGraph(e, 0, Color.BurlyWood, Color.Firebrick)
    End Sub
    Shared Sub DrawBarGraph(ByVal e As BeforeDrawXYPlotEventArgs, ByVal baseYValue As Double, ByVal outlineColor As Color, ByVal fillColor As Color)
    Dim plot As XYPlot = e.Plot
    Dim g As Graphics = e.Graphics
    If plot.HistoryCount > 0 Then
    ' Clip the data to just what will be drawn with the current axis ranges.
    Dim xData() As Double, yData() As Double
    plot.ClipData(xData, yData)
    ' Calculate the screen coordinates of a base y value and the clipped data.
    Dim baseY As Double = CType(plot.MapPoint(e.Bounds, 0, baseYValue).Y, Double)
    Dim points As PointF() = plot.MapData(e.Bounds, xData, yData, False)
    Dim outlinePen As Pen = Nothing
    Dim fillBrush As Brush = Nothing
    Try
    outlinePen = New Pen(outlineColor)
    fillBrush = New SolidBrush(fillColor)
    ' Iterate through the mapped points and calculate the bar, fill it, and outline it
    For i As Integer = 0 To points.Length - 2
    Dim currentPoint As PointF = points(i)
    Dim nextPoint As PointF = points(i + 1)
    Dim barX As Single = currentPoint.X
    Dim barY As Single = currentPoint.Y
    Dim barWidth As Single = nextPoint.X - currentPoint.X
    Dim barHeight As Single = baseY - currentPoint.Y
    g.FillRectangle(fillBrush, barX, barY, barWidth, barHeight)
    g.DrawRectangle(outlinePen, barX, barY, barWidth, barHeight)
    Next
    Finally
    If Not outlinePen Is Nothing Then
    outlinePen.Dispose()
    outlinePen = Nothing
    End If
    If Not fillBrush Is Nothing Then
    fillBrush.Dispose()
    fillBrush = Nothing
    End If
    End Try
    ' Cancel any further drawing since we completely handled the drawing of the plot.
    e.Cancel = True
    End If
    End Sub
    Hope this helps.
    - Elton

  • How can I draw a bar graph using netbeans?

    Hello, I am quite new to java and netbeans. I have got the hang of placing controls on the forms and getting them to function.. Now I want to be able to draw a graph. Is there a way I can do this is net beans? Or is there a control that lets me draw lines into it, like the PictureBox in Visual Basic?
    Thanks

    Speedster239 wrote:
    You need to get the grapics of the frame component in order to draw on it with java.awt.Graphics.
    Use something like:
    Graphics g = frame.getGraphics();
    This is wrong. See the comment about subclassing JPanel. Demo:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class ExamplePanel extends JPanel implements ActionListener {
        private java.util.List<Shape> shapes = new ArrayList<Shape>();
        private Random rnd = new Random();
        public ExamplePanel() {
            new javax.swing.Timer(500, this).start();
        public void actionPerformed(ActionEvent evt) {
            int x = rnd.nextInt(getWidth());
            int y = rnd.nextInt(getHeight());
            shapes.add(new Rectangle(x-5, y-5, 10, 10));
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            for(Shape shape : shapes) {
                g2.draw(shape);
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    ExamplePanel comp = new ExamplePanel();
                    comp.setPreferredSize(new Dimension(400, 300));
                    JFrame f = new JFrame();
                    f.getContentPane().add(comp);
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.pack();
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }

  • How to create static line in line bar graph in obiee 11g?

    Hello,
    I have requirement where user wants to see a line in bar graph.
    Now the line is just static line, we dont have data field available to draw the line in graph.
    is there a way to create a static line in chart and show it in Line bar ombo graph??
    Thanks in advance..

    e.g. i created the static line '10' in fx and now using this column as line in line bar report , but its not displaying the line at measure of '10' in chart.
    Drag the column to measures section of graph (Line - Vertical Axis) to change this static value create an edit box prompt and pass the value to the column using Presentation Variable (as said by Fernando)
    Thanks,
    Saichand

  • Bar graph error

    I made a program that shows bar graphs, well it's suppose to. Its not working, the compiler says something about the for statements needing ';'s...
    help please!
    import java.awt.*;
    import java.applet.*;
    import java.awt.event*;
    public class Bars extends Applet implements ActionListener
         int offset = 75; //displace graph vert and horiz from origin
         int height = 150, width = 240;
         int vert_div = height/5; //vert_Div = 5
         int horiz_div = width/data.length; //horiz_div = 4 (4 entries)
         Label prompt = new Label ("Enter a value for the bar graph.");
         final static String data_label[] = {"T1","T2","T3","T4"};
         TextField input = new TextField(3);
         static int data[] = new int[4];
         int numb_entries = 1;
         public void init()
              add(prompt);
              add(input);
              resize(400,275);
              input.addActionListener(this);
         public void actionPerformed( ActionEvent e )
              int numb = new Integer(input.getText()).intValue();
              if(numb_entries<5)
                   data[numb_entries-1] = numb;
                   numb_entries++;
                   input.selectAll(); // places cursor in text box after first entry
                   if(numb_entries == 5)
                        input.removeActionListener(this);
                        remove(input); // deletes component from window
                        remove(prompt); // remove() is opposite of add()                    
         public void paint(Graphics g)
              if(numb_entries==5)
                   g.drawString("value 1 = "+data[0]+", value 2 = "+data[1] +
                                  ", value 3 = "+data[2]+", value 4 = "+data[3],70,30);
                   g.setColor(Color.black);
                   g.drawLine(offset+width,offset,offset+width,offset+height); //y-axis
                   for (int i=0;i<=5;i++) //y tick marks
                        g.drawString(String.valueOf(i*20),offset+width+10,
                                        offset+height-(i*vert_div));
                        g.drawLine(offset,offset+height-(i*vert_div),offset+width+5,
                                     offset+height-(i*vert_div)); //draws horiz gridlines
                   g.drawLine(offset,offset+height,offset+width,offset+height);//x-axis
                   for (int i=0;i<data.length;i++)
                        g.drawString(data_label,
                             offset+horiz_div*i+horiz_div/2,offset+height+20);
                        g.drawLine(offset+horiz_div*i+horiz_div/2,offset+height,
                             offset+horiz_div*i+horiz_div/2,offset+height+20); //x-ticks
                   g.setColor(Color.red);
                   for (int i=0,i<data.length;i++)
                        int bar_height = data[i]*height/100;
                        g.fillRect(offset+horiz_div*i+horiz_div/4,
                             offset+height-bar_height,horiz_div/2,bar_height);
                   resize(400,275); //paint bars and data values

    change
    import java.awt.event*;with
    import java.awt.event.*;

  • Simple Bar Graph

    What I'm trying to do is make a simple bar graph, with multiple bars of different colors and do this using an array. I create a new bar, set its size and color, and then create another bar, set its size, color and i've also moved it over 10 pixels so its not ontop of the original bar. And I'm using an array for the ractangle shap, and fillrect to fill it.
    My problem comes when I add the object to the pane ( frame.getContentPane().add(blue); )
    It only adds the last one, it doesn't add the blue bar. does getContentPane repaint the screen or something, so that the previous one doesn't show? Or am I missing something?
    Thanks for any input,
    Bar Class
    import javax.swing.JPanel;
    import java.awt.*;
    public class Bar extends JPanel
       private int[] xBar = {25, 25, 30, 30};
       private int[] yBar = {350, 100, 100, 350};
         private Color fillColor;
       public Bar()
          setBackground(Color.black);
         public void setSize(int height)
              yBar[1] = height * 10;
              yBar[2] = height * 10;     
         public void changeColor(Color colour)
              fillColor = colour;
         public void moveOver(){
              for(int i = 0; i < xBar.length;i++)
                   xBar= xBar[i] + 10;
         // Draws the bar
    public void paintComponent(Graphics gc)
    super.paintComponent(gc);
    gc.setColor(fillColor);
    gc.fillPolygon(xBar, yBar, xBar.length); // draw bar
    BarChart classimport javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.*;
    public class BarChart
    // Creates the main frame of the program.
    public static void main(String[] args)
    JFrame frame = new JFrame("Bar Chart");
              Bar red = new Bar();
              Bar blue = new Bar();
              red.setSize(9);
              red.changeColor(Color.RED);
              blue.moveOver();
              blue.setSize(5);
              blue.changeColor(Color.BLUE);
    frame.getContentPane().add(blue);
    frame.getContentPane().add(red);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
              frame.setSize(400,400);

    Ok, I've recreated the whole thing. And it seems to work well, my only problem now is that the graph seems to move on the x-coordinate randomly each time I recompile and run it. Any idea's on why it may do this? I had a friend look at it, and he said it seems to be calling the draw method multiple times, but I cant figure out how, or why it would even do that. So my question is, why is the graph shifting across the screen each time I compile it and run it?
    import javax.swing.JFrame;
    import java.io.*;
    public class BarGraphDriver
         public static void main(String[] args)
              int[] input = {5, 60, 20, 100};//Set height of each bar in the graph (number between 0 and 10
              JFrame frame = new JFrame("Bar Graph");
              BarPanel panel = new BarPanel(input);
          frame.getContentPane().add(panel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);     
              frame.setSize(600, 450);
    import javax.swing.JPanel;
    import java.awt.*;
    public class BarPanel extends JPanel
         Bar graph;
       //  Sets up the panel characteristics.
       public BarPanel(int[] values)
              JPanel panel = new JPanel();
              panel.setLayout(null);     
              graph = new Bar(values);     
          setBackground(Color.black);
       //  Draws the bar
         public void paintComponent(Graphics gc)
          super.paintComponent(gc);
              graph.draw(gc);
    import javax.swing.JPanel;
    import java.awt.*;
    public class Bar extends JPanel
       private int[] xBar = {10, 10, 60, 60};
       private int[] yBar = {300, 100, 100, 300};
         private int data[];
         private int origData[];
       public Bar( int initVal[] )
              data = new int[initVal.length];
              origData = new int[initVal.length];
              for(int i=0; i<initVal.length; i++)
                   origData[i] = initVal;          
                   data[i] = Math.abs(initVal[i] - 300);
    public void draw(Graphics gc)
              gc.setColor(Color.RED);
              gc.drawLine(10, 301, 600, 301);//horizontal redline
              gc.drawLine(10, 301, 10, 10);//vertical redline
              for(int h = 0; h<data.length; h++)
                   gc.setColor(Color.GRAY);
                   gc.drawLine(10, data[h] + 1, 600, data[h] + 1);//horizontal redline
              for (int i=0; i<data.length; i++) //countes each bar
                   for (int j=0; j<xBar.length; j++)
                        xBar[j] = xBar[j] + 60;          
                   if (data[i] >= 1 || data[i] < yBar.length)
                        for(int k = 1; k < 3; k++){
                             yBar[k] = data[i];
                   gc.setColor(Color.BLUE);
              gc.fillPolygon(xBar, yBar, yBar.length); // draw bar
                   int xText = xBar[0];
                   int yText = data[i] - 10;               
                   gc.setColor(Color.WHITE);
                   gc.drawString(" " + origData[i], xText, yText);     
    Edited by: mark2685 on Oct 31, 2008 12:10 PM
    Edited by: mark2685 on Oct 31, 2008 12:14 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Displaying a line on a Bar Graph

    Hello Friends,
    I have developed a Bar Graph using the FM 'GRAPH_MATRIX_3D'.
    Now, I need draw/display line in that Graph as a cummulatove value.
    Is this possible to show a Line in a Bar Graph?
    If so, could anyone please guide me how to proceed further.
    Please let me know any possible scenarios to show a Line in a Bar Graph.
    Thanks in advance!!!
    Best Regards,
    Prasad

    Hello Kai,
    I would like work on SAP Chart Designer tool. Could you provide me any information how to use and the steps to download this tool from SDN.
    I did not find this SAP Chart Designer tool in the SDN downloads.
    Could you please proive me the path or the steps to do this.
    Please do the needful.
    Thanks in advance!!!
    Regards
    Prasad

  • Working with bar graphs, pie graphs, etc.

    I'm working with somone who likes to create pie graphs, bar graphs and other charts. This guy is not a designer and is using Microsoft applications like Excel and PowerPoint to create these charts. My job is to bring these charts over to an ID document I'm working on. The black and white ones are no problem: I can convert them to a PDF, open them up in Photshop, and rasterize them. The color ones are screwed up. We are printing only black and one spot color, and Excel is apparently programmed to save color charts as RGB or CMYK. So my basic question is: what do you do for graphs? Is there a good application for making graphs that are design quality that knows how to do spot color? Or is it best to lay out graphs manually ID, by drawing lines, shapes and bars and coloring in the spot colors myself? Thanks.

    Illustrator.
    You should be able to bring your Excel or PowerPoint graphs into Illustrator as easily as into Photoshop.

  • A bar graph problem

    hi all,
    sorry if my question is not clear, try my best to describe.
    i currently creating a bar graph applet, where this applet take different "group" of data / value, e.g. (68, 268,2680, 28 and 8). and here the maximum value is 2680, other group may NOT so. so for being the bar graph display, i have an applet that has a "fixed" maximum width of 700, i need my bar graph to have only 10 columns and also i need to minus out 10 from each column for other purposes, so i take (700 / 10) - 10 = 60, but here come the real problem, if i take 268 * 60 = 16080, that is incorrect! That is i know that i had to divide the 700 with 1000, because (700 / 1000) - (10 / 1000) = 0.69, then 268 * 0.69 = 184.92, that seem OK! but, but it still ran out of the expected result, the bar width will be much more shorter than expected (only those higher data value), why? my code will be as follow:
       if (highestWidth >= 1001)
          maxDetector = 10000;
       else if (highestWidth >= 101)
           maxDetector = 1000;
       else if (highestWidth >= 11)
           maxDetector = 100;
       else
           maxDetector = 10;
       maxSingleWidth = (axisPanel.getWidth() / maxDetector) - (10 / (maxDetector / 10));so, at for loop:
    for (i=0; i <= 9; i++){
       barPanel.setBounds(x, y, (dataValue * maxSingleWidth), height);
    any help will be very very much appreciated!!!

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    public class BarGraph
        public BarGraph()
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new BarGraphPanel());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        public static void main(String[] args)
            new BarGraph();
    class BarGraphPanel extends JPanel
        int[] data;
        int maxValue;
        Font font;
        NumberFormat nf;
        final int PAD = 40;
        public BarGraphPanel()
            data = new int[] { 75, 12, 23, 44, 98, 32, 53, 6 };
            font = new Font("lucida sans demibold", Font.PLAIN, 15);  // j2se 1.3+
            nf = NumberFormat.getNumberInstance();
            nf.setMaximumFractionDigits(1);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            double w = getWidth();
            double h = getHeight();
            // ordinate
            g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
            // ordinate labels
            String[] labels = getLabels();
            float labelScale = (float)(h - 2*PAD)/(labels.length - 1);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            for(int j = 0; j < labels.length; j++)
                float width = (float)font.getStringBounds(labels[j], frc).getWidth();
                float height = font.getLineMetrics(labels[j], frc).getAscent();
                float x = (PAD - width)/2;
                float y = (float)(PAD + j*labelScale + height/2);
                g2.drawString(labels[j], x, y);
            // abcissa
            g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
            // plot data
            g2.setPaint(Color.red);
            double xInc = (w - 2*PAD) / data.length;
            double yScale = getValueScale(h);
            double x1, y1, x2, y2;
            for(int j = 0; j < data.length; j++)
                x1 = PAD + j * xInc;
                y1 = h - PAD;
                x2 = x1 + xInc;
                y2 = y1 - data[j] * yScale;
                g2.draw(new Line2D.Double(x1, y1, x1, y2));    // left vertical
                g2.draw(new Line2D.Double(x1, y2, x2, y2));    // top of bar
                g2.draw(new Line2D.Double(x2, y2, x2, y1));    // right vertical
        private double getValueScale(double h)
            int max = getMaxValue();
            return (h - 2*PAD) / max;
        private int getMaxValue()
            int max = Integer.MIN_VALUE;
            for(int j = 0; j < data.length; j++)
                if(data[j] > max)
                    max = data[j];
            return max;
        private String[] getLabels()
            int max = getMaxValue();
            double inc = max/3d;
            double next = max;
            String[] s = new String[4];
            for(int j = 0; j < 4; j++)
                s[j] = nf.format(next - j * inc);
            return s;
    }

  • Crating bar graphs and pie charts

    hi every body
    in my application there is a need of bar graphs and pie charts can any body help me how to draw them

    try http://www.jfree.org/jfreechart/

  • Could you please give me the method to draw Line Graph in detail?

    Could you please give me the method to draw Line Graph in detail?

    Hi,
    First update your username instead of using that number.
    and also provide full information like
    Apex version
    Database version
    I am giving you one link related to charts,
    http://dgielis.blogspot.in/2011/02/apex-4-bug-series-type-bar-line-marker.html
    Hope this will helps you
    Thanks and Regards
    Jitendra

  • Need help to draw a graph from the output I get with my program please

    Hi all,
    I please need help with this program, I need to display the amount of money over the years (which the user has to enter via the textfields supplied)
    on a graph, I'm not sure what to do further with my program, but I have created a test with a System.out.println() method just to see if I get the correct output and it looks fine.
    My question is, how do I get the input that was entered by the user (the initial deposit amount as well as the number of years) and using these to draw up the graph? (I used a button for the user to click after he/she has entered both the deposit and year values to draw the graph but I don't know how to get this to work?)
    Please help me.
    The output that I got looked liked this: (just for a test!) - basically this kind of output must be shown on the graph...
    The initial deposit made was: 200.0
    After year: 1        Amount is:  210.00
    After year: 2        Amount is:  220.50
    After year: 3        Amount is:  231.53
    After year: 4        Amount is:  243.10
    After year: 5        Amount is:  255.26
    After year: 6        Amount is:  268.02
    After year: 7        Amount is:  281.42
    After year: 8        Amount is:  295.49
    After year: 9        Amount is:  310.27
    After year: 10        Amount is:  325.78
    After year: 11        Amount is:  342.07
    After year: 12        Amount is:  359.17
    After year: 13        Amount is:  377.13
    After year: 14        Amount is:  395.99
    After year: 15        Amount is:  415.79
    After year: 16        Amount is:  436.57
    After year: 17        Amount is:  458.40And here is my code that Iv'e done so far:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.Math;
    import java.text.DecimalFormat;
    public class CompoundInterestProgram extends JFrame implements ActionListener {
        JLabel amountLabel = new JLabel("Please enter the initial deposit amount:");
        JTextField amountText = new JTextField(5);
        JLabel yearsLabel = new JLabel("Please enter the numbers of years:");
        JTextField yearstext = new JTextField(5);
        JButton drawButton = new JButton("Draw Graph");
        public CompoundInterestProgram() {
            super("Compound Interest Program");
            setSize(500, 500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            amountText.addActionListener(this);
            yearstext.addActionListener(this);
            JPanel panel = new JPanel();
            panel.setBackground(Color.white);
            panel.add(amountLabel);
            amountLabel.setToolTipText("Range of deposit must be 20 - 200!");
            panel.add(amountText);
            panel.add(yearsLabel);
            yearsLabel.setToolTipText("Range of years must be 1 - 25!");
            panel.add(yearstext);
            panel.add(drawButton);
            add(panel);
            setVisible(true);
            public static void main(String[] args) {
                 DecimalFormat dec2 = new DecimalFormat( "0.00" );
                CompoundInterestProgram cip1 = new CompoundInterestProgram();
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(new GraphPanel());
                f.setSize(500, 500);
                f.setLocation(200,200);
                f.setVisible(true);
                Account a = new Account(200);
                System.out.println("The initial deposit made was: " + a.getBalance() + "\n");
                for (int year = 1; year <= 17; year++) {
                      System.out.println("After year: " + year + "   \t" + "Amount is:  " + dec2.format(a.getBalance() + a.calcInterest(year)));
              @Override
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
    class Account {
        double balance = 0;
        double interest = 0.05;
        public Account() {
             balance = 0;
             interest = 0.05;
        public Account(int deposit) {
             balance = deposit;
             interest = 0.05;
        public double calcInterest(int year) {
               return  balance * Math.pow((1 + interest), year) - balance;
        public double getBalance() {
              return balance;
    class GraphPanel extends JPanel {
        public GraphPanel() {
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.red);
    }Your help would be much appreciated.
    Thanks in advance.

    watertownjordan wrote:
    http://www.jgraph.com/jgraph.html
    The above is also good.Sorry but you need to look a bit more closely at URLs that you cite. What the OP wants is a chart (as in X against Y) not a graph (as in links and nodes) . 'jgraph' deals with links and nodes.
    The best free charting library that I know of is JFreeChart from www.jfree.org.

  • Using the report generation toolkit, how do I make a bar graph verticle instead of horizontle?

    The attached vi is similar to what I am using, and it produces an Excel bar chart. I would really like to create the same chart, only vertically instead of horizontly. I have tried all kinds of things that don't work. Is there a way to do this that does work. I want a result similar to rotating the produced chart 90 degrees CCW.
    Thank you!
    Attachments:
    Chart Test.vi ‏20 KB

    you want to use a xy-graph.
    you can right click the plot legend to make a bar graph vertical.
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    bargraph2.jpg ‏91 KB

  • BO 4.0 webi: Conditional formatting on a bar graph

    Hi,
    Is it possible to fiormat a Bar graph conditionally in BO 4.0(SAP BO BI: web intelligence)..
    I want to create a bar graph that displays bar in Green color if the value of bar is greater than target set and Red if it is less than target, which is not doable with BO xi3.1 version.
    Please let me know if this can be doable with latest version of BO 4.0 webi.
    Thanks in advance..

    Hi Bharath,
    One workaround in 3.1 I have found is to use a stacked bar chart and then create two variables out of the measure you want to be green if over a certain amount and make the formula:
    =[Measure Object] Where([Measure Object] >= 10,000)
    and the 2nd variable formula for red:
    =[Measure Object] Where ([Measure Object] <10,000)
    Then place these two measure variables on top of each other where the measure values go. Then go into the color palette and make a custom palette with the first two colors green and red see if that gives you what you are looking for.
    Thanks

  • How to use a single variable in multiple schedules in bar graph

    Hello Experts,
    I am usiing a variable X in different schedules for creating a bar graph.This variable X is used in all schedules with different restrictions.For that reason I have to use X and follow some space after X to use it in another schedule. Is there any method to use X again base on schedule name? For example: If schedule1 then X where key=1000 and if schedule2 then X where key=2000.

    Hi,
    You can create a variable with the same name but use this in a small case...
    All the Best,
    Madhu....

Maybe you are looking for