question

  • To: visad-list@xxxxxxxxxxxxx
  • Subject: question
  • From: rsoni@xxxxxxxxxxxx via smtpd (for ssec.wisc.edu [144.92.108.61]) with SMTP; 14 Aug 2001 18:35:15 UT id <QC4H0LGV>; Tue, 14 Aug 2001 11:35:41 -0700
  • Date: Tue, 14 Aug 2001 11:35:39 -0700
Hi, I sent a post earlier about displaying a histogram. So I took the
example code given by a previous histogram question and tried to display it
using scalar maps and such, but the plot displayed a line and not a
histogram.  Whats wrong with this code and how do i get to show a real
histogram?

Ravin Soni

import visad.*;
import visad.java3d.DisplayImplJ3D;
import visad.java2d.DisplayImplJ2D;
import java.rmi.RemoteException;
import java.awt.Font;
import javax.swing.*;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class Histogram {

  private RealType time, height;

  private FunctionType func_time_height;

  private visad.Set time_set;

  private FlatField vals_ff;

  private DataReferenceImpl data_ref;

  private DisplayImpl display;
  private ScalarMap distanceToOutMap, numLinksMap;

  public Histogram() throws RemoteException, VisADException
  {
       init();
  }

  // The constructor for our example class

  public void init() throws RemoteException, VisADException {


    RealType numLinks = RealType.Generic;
    RealType distanceToOut = RealType.Generic;

    FunctionType func_distanceToOut_numLinks = new
FunctionType(distanceToOut, numLinks);

    Linear1DSet distanceToOut_set = new Linear1DSet(0, 1, 10000);
    float[][] NumL_vals = new float[1][10000];
    for (int i=0;i<10000;i++) NumL_vals[0][i]=(float) Math.random();

    FlatField vals_ff = new FlatField( func_distanceToOut_numLinks,
distanceToOut_set);
    vals_ff.setSamples( NumL_vals );

    Linear1DSet bins = new Linear1DSet(0.05, 0.95, 10);

    FlatField hist = visad.math.Histogram.makeHistogram(vals_ff, bins);

    numLinksMap = new ScalarMap( numLinks, Display.YAxis );
    distanceToOutMap = new ScalarMap( distanceToOut, Display.XAxis );

    //create display
    display = new DisplayImplJ2D("display1");

    // Get display's graphics mode control and draw scales
    GraphicsModeControl dispGMC = (GraphicsModeControl)
display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);

    // Add maps to display

    display.addMap( numLinksMap );
    display.addMap( distanceToOutMap );


    // Create a data reference and set the FlatField as our data

    data_ref = new DataReferenceImpl("data_ref");

    data_ref.setData( hist );

    // Add reference to display

    display.addReference( data_ref );


    // Create application window, put display into it

    JFrame jframe = new JFrame();
    jframe.getContentPane().add(display.getComponent());


    // Set window size and make it visible

    jframe.setSize(300, 300);
    jframe.setVisible(true);

  }

  public static void main(String[] args) throws VisADException,
RemoteException
  {
      new Histogram();
  }
}


  • Follow-Ups:
    • Re: question
      • From: From: Bill Hibbard <hibbard@xxxxxxxxxxxxxxxxx>
  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: