1 42 43 package org.jfree.chart.demo; 44 45 import org.jfree.data.AbstractSeriesDataset; 46 import org.jfree.data.DatasetChangeEvent; 47 import org.jfree.data.XYDataset; 48 49 57 public class SampleXYDataset extends AbstractSeriesDataset implements XYDataset { 58 59 60 private double translate; 61 62 65 public SampleXYDataset() { 66 this.translate = 0.0; 67 } 68 69 74 public double getTranslate() { 75 return this.translate; 76 } 77 78 83 public void setTranslate(double translate) { 84 this.translate = translate; 85 notifyListeners(new DatasetChangeEvent(this, this)); 86 } 87 88 96 public Number getXValue(int series, int item) { 97 return new Double (-10.0 + translate + (item / 10.0)); 98 } 99 100 108 public Number getYValue(int series, int item) { 109 if (series == 0) { 110 return new Double (Math.cos(-10.0 + translate + (item / 10.0))); 111 } 112 else { 113 return new Double (2 * (Math.sin(-10.0 + translate + (item / 10.0)))); 114 } 115 } 116 117 122 public int getSeriesCount() { 123 return 2; 124 } 125 126 133 public String getSeriesName(int series) { 134 if (series == 0) { 135 return "y = cosine(x)"; 136 } 137 else if (series == 1) { 138 return "y = 2*sine(x)"; 139 } 140 else { 141 return "Error"; 142 } 143 } 144 145 152 public int getItemCount(int series) { 153 return 200; 154 } 155 156 } 157 158 159 160 161 162 163 164 | Popular Tags |