ui/src/main/java/ucar/nc2/ui/op/VariablePlot.java
public void setVariable(Variable v) throws IOException {
    log.info("variable " + v.getShortName());

    AbstractIntervalXYDataset dataset = null;

    Dimension dim = v.getDimension(0);
    String dimName = dim.getShortName();

    Attribute title = file.findGlobalAttribute("title");
    if (title != null)
      chart.setTitle(title.getStringValue());
    
    Variable varXdim = file.findVariable(null, dimName);
    boolean hasXdim = false;
    if (varXdim != null)
    	hasXdim = true;
    
    boolean xIsTime = false;

    XYPlot p = chart.getXYPlot();
    if (hasXdim)
    {
	    Attribute xUnit = varXdim.findAttribute("units");
	    Attribute xAxis = varXdim.findAttribute("axis");
	    if (xUnit != null)
	    	if (xUnit.getStringValue().contains("since"))
	    		xIsTime = true;
	    if (xAxis != null)
	    	if (xAxis.getStringValue().equals("T"))
	    		xIsTime = true;
	    if (xUnit != null)
	    	p.getDomainAxis().setLabel(xUnit.getStringValue());
	    else
	    	p.getDomainAxis().setLabel(dimName);

        if (xAxis != null)
	        log.info("X axis type " + xUnit.getDataType() + " value " + xUnit.toString() + " is Time " + xIsTime);
    }

    int ax = 0;
    log.info("dataset count " + p.getDatasetCount());
    if (p.getDatasetCount() >= 1)
    {
    	if (p.getDataset(p.getDatasetCount()-1) != null)
    	{
		    log.info("number in dataset " + p.getDataset(0));
		    ax = p.getDatasetCount();
		    if (ax > 0)
		    {
		    	p.setRangeAxis(ax, new NumberAxis());
		    }
    	}
    }
    log.info("axis number " + ax);
    
    final XYItemRenderer renderer = p.getRenderer();
    if (xIsTime)
    {
        final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"));
        renderer.setBaseToolTipGenerator(g);
    	
    	dataset = new TimeSeriesCollection();
    }
    else
    {
        final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"));
        renderer.setBaseToolTipGenerator(g);

        dataset = new XYSeriesCollection();
        p.setDomainAxis(new NumberAxis()); // change to NumberAxis from DateAxis which is what is created
    }
    p.getRangeAxis(ax).setAutoRange(true);
    
    Attribute vUnit = v.findAttribute("units");
    Attribute vfill = v.findAttribute("_FillValue");
    double dfill = Double.NaN;
    if (vfill != null)
      dfill = vfill.getNumericValue().doubleValue();

    if (vUnit != null)
    	p.getRangeAxis(ax).setLabel(vUnit.getStringValue());

    NetcdfDataset fds = new NetcdfDataset(file);

    CoordinateAxis1DTime tm = null;
    List<CalendarDate> dates = null;
    Array varXarray = null;
    
    if (hasXdim)
    {
    	varXarray = varXdim.read();
	    if (xIsTime)
	    {
		    tm = CoordinateAxis1DTime.factory(fds, new VariableDS(null, varXdim, true), null);
		    dates = tm.getCalendarDates();
	    }
    }
    
    Array a = v.read();

    Index idx = a.getIndex();
    idx.setCurrentCounter(0);

    int d2 = 1;
    int rank = idx.getRank();
    for (int k = 1; k < rank; k++) {
      d2 *= idx.getShape(k);
    }
    log.info("variable : " + v.getShortName() + " : dims " + v.getDimensionsString() + " rank " + rank + " d2 " + d2);

    double max = -1000;
    double min = 1000;

    for (int j = 0; j < d2; j++) {
      if (rank > 1)
        idx.set1(j); // this wont work for 3rd dimension > 1
      
      String name = v.getShortName();
      if (d2 > 1)
        name += "-" + j;

      Series s1;
      if (xIsTime)
    	  s1 = new TimeSeries(name);
      else
    	  s1 = new XYSeries(name);
      
      for (int i = 0; i < idx.getShape(0); i++) {
        idx.set0(i);
        float f = a.getFloat(idx);
        if (f != dfill) {
        	if (!Float.isNaN(f))
        	{
	        	max = Math.max(max,  f);
	        	min = Math.min(min,  f);
        	}
        	if (xIsTime)
        	{
        		Date ts = new Date(dates.get(i).getMillis());
        		((TimeSeries)s1).addOrUpdate(new Second(ts), f);
        	}
        	else if (hasXdim)
        	{
        		((XYSeries)s1).addOrUpdate(varXarray.getDouble(i), f);        		
        	}
        	else
        	{
        		((XYSeries)s1).addOrUpdate(i, f);        		        		
        	}
        }
      }
	  if (dataset instanceof TimeSeriesCollection)		  
		  ((TimeSeriesCollection)dataset).addSeries((TimeSeries)s1);
	  if (dataset instanceof XYSeriesCollection)		  
		  ((XYSeriesCollection)dataset).addSeries((XYSeries)s1);
    }
    final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true, false); 
    p.setRenderer(ax, renderer1);

    log.info("dataset " + ax + " max " + max + " min " + min + " : " + dataset);
    p.setDataset(ax, dataset);
    p.mapDatasetToRangeAxis(ax, ax);
    p.getRangeAxis(ax).setLowerBound(min);
    p.getRangeAxis(ax).setUpperBound(max);

  }
public void setVariable(Variable v) throws IOException {
    log.info("variable " + v.getShortName());

    AbstractIntervalXYDataset dataset = null;

    Dimension dim = v.getDimension(0);
    String dimName = dim.getShortName();

    Attribute title = file.findGlobalAttribute("title");
    if (title != null)
      chart.setTitle(title.getStringValue());
    
    Variable varXdim = file.findVariable(null, dimName);
    boolean hasXdim = false;
    if (varXdim != null)
    	hasXdim = true;
    
    boolean xIsTime = false;

    XYPlot p = chart.getXYPlot();
    if (hasXdim)
    {
	    Attribute xUnit = varXdim.findAttribute("units");
	    Attribute xAxis = varXdim.findAttribute("axis");
	    if (xUnit != null)
	    	if (xUnit.getStringValue().contains("since"))
	    		xIsTime = true;
	    if (xAxis != null)
	    	if (xAxis.getStringValue().equals("T"))
	    		xIsTime = true;
	    if (xUnit != null)
	    	p.getDomainAxis().setLabel(xUnit.getStringValue());
	    else
	    	p.getDomainAxis().setLabel(dimName);

        if (xAxis != null)
	        log.info("X axis type " + xUnit.getDataType() + " value " + xUnit.toString() + " is Time " + xIsTime);
    }

    int ax = 0;
    log.info("dataset count " + p.getDatasetCount());
    if (p.getDatasetCount() >= 1)
    {
    	if (p.getDataset(p.getDatasetCount()-1) != null)
    	{
		    log.info("number in dataset " + p.getDataset(0));
		    ax = p.getDatasetCount();
		    if (ax > 0)
		    {
		    	p.setRangeAxis(ax, new NumberAxis());
		    }
    	}
    }
    log.info("axis number " + ax);
    
    final XYItemRenderer renderer = p.getRenderer();
    if (xIsTime)
    {
        final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"));
        renderer.setBaseToolTipGenerator(g);
    	
    	dataset = new TimeSeriesCollection();
    }
    else
    {
        final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"));
        renderer.setBaseToolTipGenerator(g);

        dataset = new XYSeriesCollection();
        p.setDomainAxis(new NumberAxis()); // change to NumberAxis from DateAxis which is what is created
    }
    p.getRangeAxis(ax).setAutoRange(true);
    
    Attribute vUnit = v.findAttribute("units");
    Attribute vfill = v.findAttribute("_FillValue");
    double dfill = Double.NaN;
    if (vfill != null)
      dfill = vfill.getNumericValue().doubleValue();

    if (vUnit != null)
    	p.getRangeAxis(ax).setLabel(vUnit.getStringValue());

    NetcdfDataset fds = new NetcdfDataset(file);

    CoordinateAxis1DTime tm = null;
    List<CalendarDate> dates = null;
    Array varXarray = null;
    
    if (hasXdim)
    {
    	varXarray = varXdim.read();
	    if (xIsTime)
	    {
		    tm = CoordinateAxis1DTime.factory(fds, new VariableDS(null, varXdim, true), null);
		    dates = tm.getCalendarDates();
	    }
    }
    
    Array a = v.read();

    Index idx = a.getIndex();
    idx.setCurrentCounter(0);

    int d2 = 1;
    int rank = idx.getRank();
    for (int k = 1; k < rank; k++) {
      d2 *= idx.getShape(k);
    }
    log.info("variable : " + v.getShortName() + " : dims " + v.getDimensionsString() + " rank " + rank + " d2 " + d2);

    double max = -1000;
    double min = 1000;

    for (int j = 0; j < d2; j++) {
      if (rank > 1)
        idx.set1(j); // this wont work for 3rd dimension > 1
      
      String name = v.getShortName();
      if (d2 > 1)
        name += "-" + j;

      Series s1;
      if (xIsTime)
    	  s1 = new TimeSeries(name);
      else
    	  s1 = new XYSeries(name);
      
      for (int i = 0; i < idx.getShape(0); i++) {
        idx.set0(i);
        float f = a.getFloat(idx);
        if (f != dfill) {
        	if (!Float.isNaN(f))
        	{
	        	max = Math.max(max,  f);
	        	min = Math.min(min,  f);
        	}
        	if (xIsTime)
        	{
        		Date ts = new Date(dates.get(i).getMillis());
        		((TimeSeries)s1).addOrUpdate(new Second(ts), f);
        	}
        	else if (hasXdim)
        	{
        		((XYSeries)s1).addOrUpdate(varXarray.getDouble(i), f);        		
        	}
        	else
        	{
        		((XYSeries)s1).addOrUpdate(i, f);        		        		
        	}
        }
      }
	  if (dataset instanceof TimeSeriesCollection)		  
		  ((TimeSeriesCollection)dataset).addSeries((TimeSeries)s1);
	  if (dataset instanceof XYSeriesCollection)		  
		  ((XYSeriesCollection)dataset).addSeries((XYSeries)s1);
    }
    final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true, false); 
    p.setRenderer(ax, renderer1);

    log.info("dataset " + ax + " max " + max + " min " + min + " : " + dataset);
    p.setDataset(ax, dataset);
    p.mapDatasetToRangeAxis(ax, ax);
    p.getRangeAxis(ax).setLowerBound(min);
    p.getRangeAxis(ax).setUpperBound(max);

  }
public void setVariable ( Variable v ) throws IOException { log . info ( "variable " + v . getShortName ( ) ) ; AbstractIntervalXYDataset dataset = null ; Dimension dim = v . getDimension ( 0 ) ; String dimName = dim . getShortName ( ) ; Attribute title = file . findGlobalAttribute ( "title" ) ; if ( title != null ) chart . setTitle ( title . getStringValue ( ) ) ; Variable varXdim = file . findVariable ( null , dimName ) ; boolean hasXdim = false ; if ( varXdim != null ) hasXdim = true ; boolean xIsTime = false ; XYPlot p = chart . getXYPlot ( ) ; if ( hasXdim ) { Attribute xUnit = varXdim . findAttribute ( "units" ) ; Attribute xAxis = varXdim . findAttribute ( "axis" ) ; if ( xUnit != null ) if ( xUnit . getStringValue ( ) . contains ( "since" ) ) xIsTime = true ; if ( xAxis != null ) if ( xAxis . getStringValue ( ) . equals ( "T" ) ) xIsTime = true ; if ( xUnit != null ) p . getDomainAxis ( ) . setLabel ( xUnit . getStringValue ( ) ) ; else p . getDomainAxis ( ) . setLabel ( dimName ) ; if ( xAxis != null ) log . info ( "X axis type " + xUnit . getDataType ( ) + " value " + xUnit . toString ( ) + " is Time " + xIsTime ) ; } int ax = 0 ; log . info ( "dataset count " + p . getDatasetCount ( ) ) ; if ( p . getDatasetCount ( ) >= 1 ) { if ( p . getDataset ( p . getDatasetCount ( ) - 1 ) != null ) { log . info ( "number in dataset " + p . getDataset ( 0 ) ) ; ax = p . getDatasetCount ( ) ; if ( ax > 0 ) { p . setRangeAxis ( ax , new NumberAxis ( ) ) ; } } } log . info ( "axis number " + ax ) ; final XYItemRenderer renderer = p . getRenderer ( ) ; if ( xIsTime ) { final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator ( StandardXYToolTipGenerator . DEFAULT_TOOL_TIP_FORMAT , new SimpleDateFormat ( "d-MMM-yyyy" ) , new DecimalFormat ( "0.00" ) ) ; renderer . setBaseToolTipGenerator ( g ) ; dataset = new TimeSeriesCollection ( ) ; } else { final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator ( StandardXYToolTipGenerator . DEFAULT_TOOL_TIP_FORMAT , new DecimalFormat ( "0.00" ) , new DecimalFormat ( "0.00" ) ) ; renderer . setBaseToolTipGenerator ( g ) ; dataset = new XYSeriesCollection ( ) ; p . setDomainAxis ( new NumberAxis ( ) ) ; // change to NumberAxis from DateAxis which is what is created } p . getRangeAxis ( ax ) . setAutoRange ( true ) ; Attribute vUnit = v . findAttribute ( "units" ) ; Attribute vfill = v . findAttribute ( "_FillValue" ) ; double dfill = Double . NaN ; if ( vfill != null ) dfill = vfill . getNumericValue ( ) . doubleValue ( ) ; if ( vUnit != null ) p . getRangeAxis ( ax ) . setLabel ( vUnit . getStringValue ( ) ) ; NetcdfDataset fds = new NetcdfDataset ( file ) ; CoordinateAxis1DTime tm = null ; List < CalendarDate > dates = null ; Array varXarray = null ; if ( hasXdim ) { varXarray = varXdim . read ( ) ; if ( xIsTime ) { tm = CoordinateAxis1DTime . factory ( fds , new VariableDS ( null , varXdim , true ) , null ) ; dates = tm . getCalendarDates ( ) ; } } Array a = v . read ( ) ; Index idx = a . getIndex ( ) ; idx . setCurrentCounter ( 0 ) ; int d2 = 1 ; int rank = idx . getRank ( ) ; for ( int k = 1 ; k < rank ; k ++ ) { d2 *= idx . getShape ( k ) ; } log . info ( "variable : " + v . getShortName ( ) + " : dims " + v . getDimensionsString ( ) + " rank " + rank + " d2 " + d2 ) ; double max = - 1000 ; double min = 1000 ; for ( int j = 0 ; j < d2 ; j ++ ) { if ( rank > 1 ) idx . set1 ( j ) ; // this wont work for 3rd dimension > 1 String name = v . getShortName ( ) ; if ( d2 > 1 ) name += "-" + j ; Series s1 ; if ( xIsTime ) s1 = new TimeSeries ( name ) ; else s1 = new XYSeries ( name ) ; for ( int i = 0 ; i < idx . getShape ( 0 ) ; i ++ ) { idx . set0 ( i ) ; float f = a . getFloat ( idx ) ; if ( f != dfill ) { if ( ! Float . isNaN ( f ) ) { max = Math . max ( max , f ) ; min = Math . min ( min , f ) ; } if ( xIsTime ) { Date ts = new Date ( dates . get ( i ) . getMillis ( ) ) ; ( ( TimeSeries ) s1 ) . addOrUpdate ( new Second ( ts ) , f ) ; } else if ( hasXdim ) { ( ( XYSeries ) s1 ) . addOrUpdate ( varXarray . getDouble ( i ) , f ) ; } else { ( ( XYSeries ) s1 ) . addOrUpdate ( i , f ) ; } } } if ( dataset instanceof TimeSeriesCollection ) ( ( TimeSeriesCollection ) dataset ) . addSeries ( ( TimeSeries ) s1 ) ; if ( dataset instanceof XYSeriesCollection ) ( ( XYSeriesCollection ) dataset ) . addSeries ( ( XYSeries ) s1 ) ; } final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer ( true , false ) ; p . setRenderer ( ax , renderer1 ) ; log . info ( "dataset " + ax + " max " + max + " min " + min + " : " + dataset ) ; p . setDataset ( ax , dataset ) ; p . mapDatasetToRangeAxis ( ax , ax ) ; p . getRangeAxis ( ax ) . setLowerBound ( min ) ; p . getRangeAxis ( ax ) . setUpperBound ( max ) ; }
assume first dimension is TIME series
assume first dimension is TIME series