1 41 42 package org.jfree.chart.labels; 43 44 import java.io.Serializable ; 45 46 import org.jfree.data.XYDataset; 47 import org.jfree.data.XisSymbolic; 48 import org.jfree.data.YisSymbolic; 49 import org.jfree.data.time.RegularTimePeriod; 50 import org.jfree.data.time.TimeSeriesCollection; 51 import org.jfree.util.PublicCloneable; 52 53 58 public class SymbolicXYToolTipGenerator implements XYToolTipGenerator, 59 Cloneable , PublicCloneable, 60 Serializable { 61 62 71 public String generateToolTip(XYDataset data, int series, int item) { 72 73 String x, y; 74 if (data instanceof YisSymbolic) { 75 y = ((YisSymbolic) data).getYSymbolicValue(series, item); 76 } 77 else { 78 Number n = data.getYValue(series, item); 79 y = Double.toString(round(n.doubleValue(), 2)); 80 } 81 if (data instanceof XisSymbolic) { 82 x = ((XisSymbolic) data).getXSymbolicValue(series, item); 83 } 84 else if (data instanceof TimeSeriesCollection) { 85 RegularTimePeriod p 86 = ((TimeSeriesCollection) data).getSeries(series).getTimePeriod(item); 87 x = p.toString(); 88 } 89 else { 90 Number n = data.getXValue(series, item); 91 x = Double.toString(round(n.doubleValue(), 2)); 92 } 93 return "X: " + x + ", Y: " + y; 94 } 95 96 104 private static double round(double value, int nb) { 105 if (nb <= 0) { 106 return Math.floor(value + 0.5d); 107 } 108 double p = Math.pow(10, nb); 109 double tempval = Math.floor(value * p + 0.5d); 110 return tempval / p; 111 } 112 113 120 public Object clone() throws CloneNotSupportedException { 121 122 return super.clone(); 123 124 } 125 126 133 public boolean equals(Object o) { 134 135 if (o == null) { 136 return false; 137 } 138 if (o == this) { 139 return true; 140 } 141 142 if (o instanceof SymbolicXYToolTipGenerator) { 143 return true; 144 } 145 return false; 146 147 } 148 149 } 150 | Popular Tags |