Example #1
0
 public static ScatterPlot demo(String data, String xfield, String yfield, String sfield) {
   Table table = null;
   try {
     table = new DelimitedTextTableReader().readTable(data);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
   ScatterPlot scatter = new ScatterPlot(table, xfield, yfield, sfield);
   scatter.setPointSize(10);
   return scatter;
 }
Example #2
0
  private static JToolBar getEncodingToolbar(
      final ScatterPlot sp, final String xfield, final String yfield, final String sfield) {
    int spacing = 10;

    // create list of column names
    Table t = (Table) sp.getVisualization().getSourceData(group);
    String[] colnames = new String[t.getColumnCount()];
    for (int i = 0; i < colnames.length; ++i) colnames[i] = t.getColumnName(i);

    // create toolbar that allows visual mappings to be changed
    JToolBar toolbar = new JToolBar();
    toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
    toolbar.add(Box.createHorizontalStrut(spacing));

    final JComboBox xcb = new JComboBox(colnames);
    xcb.setSelectedItem(xfield);
    xcb.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Visualization vis = sp.getVisualization();
            AxisLayout xaxis = (AxisLayout) vis.getAction("x");
            xaxis.setDataField((String) xcb.getSelectedItem());
            vis.run("draw");
          }
        });
    toolbar.add(new JLabel("X: "));
    toolbar.add(xcb);
    toolbar.add(Box.createHorizontalStrut(2 * spacing));

    final JComboBox ycb = new JComboBox(colnames);
    ycb.setSelectedItem(yfield);
    ycb.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Visualization vis = sp.getVisualization();
            AxisLayout yaxis = (AxisLayout) vis.getAction("y");
            yaxis.setDataField((String) ycb.getSelectedItem());
            vis.run("draw");
          }
        });
    toolbar.add(new JLabel("Y: "));
    toolbar.add(ycb);
    toolbar.add(Box.createHorizontalStrut(2 * spacing));

    final JComboBox scb = new JComboBox(colnames);
    scb.setSelectedItem(sfield);
    scb.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Visualization vis = sp.getVisualization();
            DataShapeAction s = (DataShapeAction) vis.getAction("shape");
            s.setDataField((String) scb.getSelectedItem());
            vis.run("draw");
          }
        });
    toolbar.add(new JLabel("Shape: "));
    toolbar.add(scb);
    toolbar.add(Box.createHorizontalStrut(spacing));
    toolbar.add(Box.createHorizontalGlue());

    return toolbar;
  }