List of usage examples for org.jfree.data.xy XYIntervalSeries getDataItem
@Override public ComparableObjectItem getDataItem(int index)
From source file:it.cnr.istc.iloc.gui.TimelinesChart.java
public TimelinesChart() { super(CHART); setBorder(null);//w w w. jav a2s . c o m addTimelineVisualizer(new StateVariableVisualizer()); addChartMouseListener(new ChartMouseListener() { private Object getDataItem(ChartEntity entity) { XYItemEntity e = ((XYItemEntity) entity); XYDataset ds = e.getDataset(); if (ds instanceof XYIntervalSeriesCollection) { XYIntervalSeries theSerie = ((XYIntervalSeriesCollection) ds).getSeries(e.getSeriesIndex()); return theSerie.getDataItem(e.getItem()); } else if (ds instanceof XYSeriesCollection) { XYSeries theSerie = ((XYSeriesCollection) ds).getSeries(e.getSeriesIndex()); return theSerie.getDataItem(e.getItem()); } else { return null; } } @Override public void chartMouseClicked(ChartMouseEvent cme) { if (cme.getEntity() != null && cme.getEntity() instanceof XYItemEntity) { Object dataItem = getDataItem(cme.getEntity()); visualizers.values().forEach(visualizer -> { visualizer.mouseClicked(dataItem); }); } } @Override public void chartMouseMoved(ChartMouseEvent cme) { if (cme.getEntity() != null && cme.getEntity() instanceof XYItemEntity) { setCursor(HAND_CURSOR); } else { setCursor(DEFAULT_CURSOR); } } }); }
From source file:userinterface.graph.Histogram.java
/** * Exports our Histogram to a GNU plot readable file * /*from ww w .j ava2 s . c om*/ * @param file The file to which the data has to be written * @throws IOException */ public void exportToGnuplot(File file) throws IOException { PrintWriter out = new PrintWriter(new FileWriter(file)); //add some info for the users out.println("#========================================="); out.println("# Generated by PRISM Chart Package"); out.println("#========================================="); out.println("# usage: gnuplot <filename>"); out.println("# Written by Muhammad Omer Saeed <muhammad.omar555@gmail.com>"); out.println(); //set some properties out.println("set xtics rotate out"); out.println("set auto x"); out.println("set yrange " + "[0:" + getChart().getXYPlot().getRangeAxis().getRange().getUpperBound() * 1.2 + "]"); out.println("set style data histogram"); out.println("set style fill solid border"); out.println("set style histogram clustered"); out.println("set boxwidth 3"); synchronized (getSeriesLock()) { for (int i = 0; i < getChart().getXYPlot().getSeriesCount(); i++) { if (i == 0) out.print("plot '-' using 2:xticlabels(1)"); else out.print(", '-' using 2:xticlabels(1)"); } out.println(); out.println(); //write the histogram data for (int i = 0; i < getAllSeriesKeys().size(); i++) { XYIntervalSeries series = keyToSeries.get(getAllSeriesKeys().get(i)); out.println("max " + series.getKey()); for (int j = 0; j < series.getItemCount(); j++) { XYIntervalDataItem item = (XYIntervalDataItem) series.getDataItem(j); double x = item.getXHighValue(); x = x * 100; x = Math.round(x); x = x / 100; out.println(x + " " + item.getYValue()); } out.println("end series"); out.println(); } } //finishing up out.println(); out.println("pause -1"); out.flush(); out.close(); }