1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
public class ChartMBean {
private XYDataList series1DataList = new XYDataList();
private XYDataList series2DataList = new XYDataList();
private XYDataList series3DataList = new XYDataList();
private int minX = 0;
private int maxX = 10;
private FlotChartRendererData chartData;
private String clickedString = "No Data Point Clicked Yet.";
private String clickedDataPointLabel = "";
private Integer clickedDataSeriesIndex = null;
private XYDataPoint clickedDataPoint = null;
public ChartMBean() {
// TODO Auto-generated constructor stub
chartData = new FlotChartRendererData();
for (int i = 0; i <= 100; i++) {
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(3);
series1DataList.addDataPoint(new XYDataPoint(i, Math.random() * 10, "Point: " + i));
series2DataList.addDataPoint(new XYDataPoint(i, Math.random() * 10, "Point: " + i));
series3DataList.addDataPoint(new XYDataPoint(i, Math.random() * 10));
}
series1DataList.setLabel("Series 1");
series2DataList.setLabel("Series 2");
series3DataList.setLabel("Series 3");
}
public XYDataSetCollection getChartSeries() {
XYDataSetCollection collection = new XYDataSetCollection();
XYDataList currentSeries1DataList = new XYDataList();
XYDataList currentSeries2DataList = new XYDataList();
XYDataList currentSeries3DataList = new XYDataList();
for (int i = minX; i <= maxX; i++) {
long startTime = 1196463600000l;
if (chartData.getMode().equalsIgnoreCase("Time")) {
XYDataPoint p1 = new XYDataPoint(series1DataList.get(i).getX(), series1DataList.get(i).getY(), series1DataList.get(i).getPointLabel());
p1.setX(startTime + (p1.getX().doubleValue() * 1000 * 60 ));
XYDataPoint p2 = new XYDataPoint(series2DataList.get(i).getX(), series2DataList.get(i).getY(), series2DataList.get(i).getPointLabel());
p2.setX(startTime + (p2.getX().doubleValue() * 1000 * 60 ));
XYDataPoint p3 = new XYDataPoint(series3DataList.get(i).getX(), series3DataList.get(i).getY(), series3DataList.get(i).getPointLabel());
p3.setX(startTime + (p3.getX().doubleValue() * 1000 * 60 ));
currentSeries1DataList.addDataPoint(p1);
currentSeries2DataList.addDataPoint(p2);
currentSeries3DataList.addDataPoint(p3);
} else {
currentSeries1DataList.addDataPoint(series1DataList.get(i));
currentSeries2DataList.addDataPoint(series2DataList.get(i));
currentSeries3DataList.addDataPoint(series3DataList.get(i));
}
}
//Copy over the meta data for each series to the current viewed-series
currentSeries1DataList.setLabel(series1DataList.getLabel());
currentSeries1DataList.setFillLines(series1DataList.isFillLines());
currentSeries1DataList.setMarkerPosition(series1DataList.getMarkerPosition());
currentSeries1DataList.setMarkers(series1DataList.isMarkers());
currentSeries1DataList.setShowDataPoints(series1DataList.isShowDataPoints());
currentSeries1DataList.setShowLines(series1DataList.isShowLines());
currentSeries2DataList.setLabel(series2DataList.getLabel());
currentSeries2DataList.setFillLines(series2DataList.isFillLines());
currentSeries2DataList.setMarkerPosition(series2DataList.getMarkerPosition());
currentSeries2DataList.setMarkers(series2DataList.isMarkers());
currentSeries2DataList.setShowDataPoints(series2DataList.isShowDataPoints());
currentSeries2DataList.setShowLines(series2DataList.isShowLines());
currentSeries3DataList.setLabel(series3DataList.getLabel());
currentSeries3DataList.setFillLines(series3DataList.isFillLines());
currentSeries3DataList.setMarkerPosition(series3DataList.getMarkerPosition());
currentSeries3DataList.setMarkers(series3DataList.isMarkers());
currentSeries3DataList.setShowDataPoints(series3DataList.isShowDataPoints());
currentSeries3DataList.setShowLines(series3DataList.isShowLines());
collection.addDataList(currentSeries1DataList);
collection.addDataList(currentSeries2DataList);
collection.addDataList(currentSeries3DataList);
return collection;
}
public XYDataList getSeries1DataList() {
return series1DataList;
}
public void setSeries1DataList(XYDataList series1DataList) {
this.series1DataList = series1DataList;
}
public XYDataList getSeries2DataList() {
return series2DataList;
}
public void setSeries2DataList(XYDataList series2DataList) {
this.series2DataList = series2DataList;
}
public XYDataList getSeries3DataList() {
return series3DataList;
}
public void setSeries3DataList(XYDataList series3DataList) {
this.series3DataList = series3DataList;
}
public FlotChartRendererData getChartData() {
return chartData;
}
public void setChartData(FlotChartRendererData chartData) {
this.chartData = chartData;
}
public String getClickedString() {
return clickedString;
}
public void setClickedString(String clickedString) {
this.clickedString = clickedString;
}
public XYDataPoint getClickedDataPoint() {
return clickedDataPoint;
}
public void setClickedDataPoint(XYDataPoint clickedDataPoint) {
this.clickedDataPoint = clickedDataPoint;
}
public String getClickedDataPointLabel() {
return clickedDataPointLabel;
}
public void setClickedDataPointLabel(String clickedDataPointLabel) {
this.clickedDataPointLabel = clickedDataPointLabel;
}
public void chartDraggedListener(ValueChangeEvent event) {
}
public void changeDataPointLabelActionListener(ActionEvent event) {
//Not much to do really...
}
public void chartActionListener(ActionEvent event) {
if (event instanceof FlotChartClickedEvent) {
FlotChartClickedEvent flotEvent = (FlotChartClickedEvent)event;
setClickedString("Chart Last Clicked at point (" + flotEvent.getClickedDataPoint().getX() + "," + flotEvent.getClickedDataPoint().getY() + "). Data Point index: " + flotEvent.getClickedDataPointIndex()
+ " on series: " + flotEvent.getClickedSeriesLabel() + ", which is series index: " + flotEvent.getClickedSeriesIndex());
clickedDataSeriesIndex = flotEvent.getClickedSeriesIndex();
Integer clickedDataPointIndex = flotEvent.getClickedDataPointIndex();
XYDataList clickedList = null;
XYDataPoint clickedPoint = null;
if (clickedDataSeriesIndex != null && clickedDataSeriesIndex.equals(0)) {
clickedList = series1DataList;
} else if (clickedDataSeriesIndex != null && clickedDataSeriesIndex.equals(1)) {
clickedList = series2DataList;
} else if (clickedDataSeriesIndex != null && clickedDataSeriesIndex.equals(2)) {
clickedList = series3DataList;
}
if (clickedDataPointIndex != null) {
clickedPoint = clickedList.get(clickedDataPointIndex);
}
if (clickedPoint != null) {
clickedDataPoint = clickedPoint;
}
} else if (event instanceof FlotChartDraggedEvent) {
FlotChartDraggedEvent dragEvent = (FlotChartDraggedEvent)event;
Double chartMoved = dragEvent.getDragValue();
if (chartData.getMode().equalsIgnoreCase("Time")) {
chartMoved /= 60000;
}
//Move the chart according to the drag-motion
minX += chartMoved;
maxX += chartMoved;
//Ensure that minX and maxX does not go out of bounds
if (minX < 0) { minX = 0; maxX = 10; }
if (maxX > 100) { maxX = 100; minX = 90;}
}
}
public void testChartDraggedAction(FlotChartDraggedEvent dragEvent) {
//Log.info("chartDraggedAction");
} |
Partager