1 49 50 package org.jfree.chart.labels; 51 52 import java.io.Serializable ; 53 54 import org.jfree.data.time.RegularTimePeriod; 55 import org.jfree.data.time.TimeSeriesCollection; 56 import org.jfree.data.xy.XYDataset; 57 import org.jfree.data.xy.XisSymbolic; 58 import org.jfree.data.xy.YisSymbolic; 59 import org.jfree.util.PublicCloneable; 60 61 67 public class SymbolicXYItemLabelGenerator implements XYItemLabelGenerator, 68 XYToolTipGenerator, 69 Cloneable , 70 PublicCloneable, 71 Serializable { 72 73 74 private static final long serialVersionUID = 3963400354475494395L; 75 76 85 public String generateToolTip(XYDataset data, int series, int item) { 86 87 String xStr, yStr; 88 if (data instanceof YisSymbolic) { 89 yStr = ((YisSymbolic) data).getYSymbolicValue(series, item); 90 } 91 else { 92 double y = data.getYValue(series, item); 93 yStr = Double.toString(round(y, 2)); 94 } 95 if (data instanceof XisSymbolic) { 96 xStr = ((XisSymbolic) data).getXSymbolicValue(series, item); 97 } 98 else if (data instanceof TimeSeriesCollection) { 99 RegularTimePeriod p 100 = ((TimeSeriesCollection) data).getSeries(series) 101 .getTimePeriod(item); 102 xStr = p.toString(); 103 } 104 else { 105 double x = data.getXValue(series, item); 106 xStr = Double.toString(round(x, 2)); 107 } 108 return "X: " + xStr + ", Y: " + yStr; 109 } 110 111 121 public String generateLabel(XYDataset dataset, int series, int category) { 122 return null; } 124 125 133 private static double round(double value, int nb) { 134 if (nb <= 0) { 135 return Math.floor(value + 0.5d); 136 } 137 double p = Math.pow(10, nb); 138 double tempval = Math.floor(value * p + 0.5d); 139 return tempval / p; 140 } 141 142 149 public Object clone() throws CloneNotSupportedException { 150 return super.clone(); 151 } 152 153 160 public boolean equals(Object obj) { 161 if (obj == this) { 162 return true; 163 } 164 if (obj instanceof SymbolicXYItemLabelGenerator) { 165 return true; 166 } 167 return false; 168 } 169 170 } 171 | Popular Tags |