List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:vis2006.VisGrafik.java
public JFreeChart createChart(Stand st, int speciesCode) { // create the dataset... int code = speciesCode; int merk = 0; for (int i = 0; i < st.nspecies; i++) if (st.sp[i].code == code) merk = i;//from w ww .j a v a 2 s . c o m XYSeriesCollection dataset = new XYSeriesCollection(); // Werte der Hhenkurve XYSeries series0 = new XYSeries("Hhenkurve: " + st.sp[merk].heightcurveUsed); for (int k = 0; k < st.ntrees; k++) { if ((st.tr[k].d > 0) && (st.tr[k].h > 0) && st.tr[k].code == code && st.tr[k].fac > 0.0) series0.add(st.tr[k].d, st.tr[k].h); } dataset.addSeries(series0); // Messwerte aus der Versuchsflche XYSeries series1 = new XYSeries("Messwerte"); for (int k = 0; k < st.ntrees; k++) { if ((st.tr[k].d > 0) && (st.tr[k].hMeasuredValue > 0) && st.tr[k].code == code && st.tr[k].fac > 0.0) series1.add(st.tr[k].d, st.tr[k].hMeasuredValue); } dataset.addSeries(series1); // Andere Messwerte (HG, nurH) XYSeries series2 = new XYSeries("Andere Hhen"); for (int k = 0; k < st.ntrees; k++) { if ((st.tr[k].d > 0) && (st.tr[k].hMeasuredValue > 0) && st.tr[k].code == code && (st.tr[k].no.contains("nurH") || st.tr[k].no.contains("HG"))) series2.add(st.tr[k].d, st.tr[k].hMeasuredValue); } dataset.addSeries(series2); /* Wozu ist die gut? double dmin=9000; double dmax=-9000; for (int k=0;k<st.ntrees;k++){ if (st.tr[k].code==st.sp[merk].code && st.tr[k].fac > 0.0){ if (dmax <st.tr[k].d ) dmax=st.tr[k].d; if (dmin >st.tr[k].d ) dmin=st.tr[k].d; } } XYSeries series3 = new XYSeries(""); int idmin = (int)(Math.round(dmin)); int idmax = (int)(Math.round(dmax))+1; for (int k=idmin;k<=idmax;k++){ double dwert=k*1.0; if (st.sp[merk].heightcurveUsed.indexOf("Einheits")>-1){ UniformHeight uh = new UniformHeight(); series3.add(dwert,uh.height(st.sp[merk],dwert, st.sp[merk].dg,st.sp[merk].hg,st)); } else { HeightCurve hc =new HeightCurve(); series3.add(dwert,hc.getHeight(st.sp[merk].spDef.heightCurve,dwert,st.sp[merk].heightcurveUsedP0, st.sp[merk].heightcurveUsedP1,st.sp[merk].heightcurveUsedP2)); } } dataset.addSeries(series3); */ // JFreeChart chart = ChartFactory.createScatterPlot("Hhenkurve " + st.sp[merk].spDef.longName, "BHD [cm]", "Hhe [m]", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, //legend false, // tooltips false); // urls XYPlot plot = chart.getXYPlot(); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setAutoRangeMinimumSize(1.0); plot.getRangeAxis().setAutoRangeMinimumSize(5.0); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); // Hhenkurve - rote Linie renderer.setSeriesStroke(0, new BasicStroke(2)); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesLinesVisible(1, false); // Parzellenmesswerte - blaue Symbole renderer.setSeriesShapesVisible(1, true); renderer.setSeriesPaint(1, Color.BLUE); renderer.setSeriesLinesVisible(2, false); // Andere Messwerte - blaue leere Symbole renderer.setSeriesShapesVisible(2, true); renderer.setSeriesShapesFilled(2, false); renderer.setSeriesPaint(2, Color.BLUE); // renderer.setSeriesLinesVisible(3, true); // renderer.setSeriesShapesVisible(3,false); // renderer.setSeriesPaint(3, Color.BLUE); // renderer.setSeriesPaint(1, new Color(st.sp[merk].spDef.colorRed,st.sp[merk].spDef.colorGreen,st.sp[merk].spDef.colorBlue)); plot.setRenderer(renderer); System.out.println("Plot done"); return chart; }
From source file:sim.app.sugarscape.util.ResultsGrapher.java
JFreeChart createChart1(XYSeries[] series) { JFreeChart chart3 = ChartFactory.createXYLineChart("Results", x_axis_fieldname, y_axis_fieldname, null, //new XYSeriesCollection(series[2]), PlotOrientation.VERTICAL, true, true, false); //System.out.println("Series count = " +series[0].getItemCount()); XYPlot plot = chart3.getXYPlot(); ValueAxis yAxis = plot.getRangeAxis(); //xAxis.setFixedDimension(100); //yAxis.setFixedDimension(1.0); //yAxis.setRange(0,1); ValueAxis xAxis = plot.getDomainAxis(); //xAxis.setFixedDimension(50); StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); renderer.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20)); renderer.setItemLabelsVisible(true); renderer.setSeriesItemLabelsVisible(1, true); renderer.setBaseShapesVisible(true); //XYLabelGenerator generator = new StandardXYLabelGenerator(); //"{2}", new DecimalFormat("0.00") ); //renderer.setLabelGenerator(generator); //NumberAxis axis2 = new NumberAxis("Average Agent Vision"); //renderer.setItemLabelsVisible(true); //axis2.setAutoRangeIncludesZero(false); //axis2.setRange(0,12); //plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision); //plot.setDataset(1, vision); //String first_letter = x_param_fieldname.substring(0,1)+"="; XYSeriesCollection xys = new XYSeriesCollection(); for (int a = 0; a < series.length; a++) { xys.addSeries(series[a]);/* ww w.ja v a 2 s . c om*/ //xys. //xys.getSeriesName(4); System.out.println(xys.getSeries(a).getDescription()); } plot.setDataset(0, xys); return chart3; }
From source file:se.six.jmeter.visualizer.statagg.StatAggVisualizer.java
private JFreeChart createChart() { setupDatasets();/* w w w . j a v a 2s . c o m*/ final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "ThroughPut", _dataSet1, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); //axis.setFixedAutoRange(12 * 3600 * 1000); // 12 Hours XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setSeriesPaint(0, Color.BLACK); final NumberAxis axis2 = new NumberAxis("Response Time"); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, _dataSet2); plot.mapDatasetToRangeAxis(1, 1); StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, new Color(0, 153, 255)); plot.setRenderer(1, renderer2); chart.setBackgroundPaint(Color.white); return chart; }
From source file:com.sciaps.view.PlotConfigPanel.java
/** * Creates new form PlotRangeSetterPanel * * @param plot//from w ww . jav a 2 s. c o m */ public PlotConfigPanel(XYPlot plot) { initComponents(); plot_ = plot; rangeAxis_ = plot.getRangeAxis(); domainAxis_ = plot.getDomainAxis(); btnLeft_.setIcon(createImageIcon("/images/left.png")); btnRight_.setIcon(createImageIcon("/images/right.png")); btnAutoRange_.setIcon(createImageIcon("/images/center.png")); btnUp_.setIcon(createImageIcon("/images/up.png")); btnDown_.setIcon(createImageIcon("/images/down.png")); mousePressed_ = false; }
From source file:org.zaproxy.zap.extension.ascan.ScanProgressDialog.java
private JFreeChart createChart(final XYDataset dataset) { JFreeChart result = ChartFactory.createTimeSeriesChart(null, // No title - it just takes up space Constant.messages.getString("ascan.progress.chart.time"), Constant.messages.getString("ascan.progress.chart.responses"), dataset, true, true, false); XYPlot plot = result.getXYPlot(); ValueAxis daxis = plot.getDomainAxis(); daxis.setAutoRange(true);/*from w w w . j av a 2s.c o m*/ daxis.setAutoRangeMinimumSize(60000.0); plot.getRangeAxis().setAutoRangeMinimumSize(20); return result; }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Translates mouse coordinates to chart coordinates (xy-axis) * // www . j ava 2s . c o m * @param myChart * @param mouseX * @param mouseY * @return Range as chart coordinates * @throws Exception */ public static Point2D mouseXYToPlotXY(ChartPanel myChart, int mouseX, int mouseY) throws Exception { Point2D p = myChart.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = null; // find plot as parent of axis ChartEntity entity = findChartEntity(myChart, mouseX, mouseY); if (entity instanceof AxisEntity) { Axis a = ((AxisEntity) entity).getAxis(); if (a.getPlot() instanceof XYPlot) plot = (XYPlot) a.getPlot(); } ChartRenderingInfo info = myChart.getChartRenderingInfo(); int subplot = info.getPlotInfo().getSubplotIndex(p); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); if (subplot != -1) dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea(); if (plot == null) plot = findXYSubplot(myChart.getChart(), info, p.getX(), p.getY()); // coordinates double cx = 0; double cy = 0; if (plot != null) { // find axis ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // parent? if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); domainAxis = pp.getDomainAxis(); domainAxisEdge = pp.getDomainAxisEdge(); } if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); rangeAxis = pp.getRangeAxis(); rangeAxisEdge = pp.getRangeAxisEdge(); } if (domainAxis != null) cx = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge); if (rangeAxis != null) cy = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge); } else { throw new Exception("no xyplot found"); } return new Point2D.Double(cx, cy); }
From source file:binky.reportrunner.ui.actions.admin.GetAuditChartAction.java
@Override @PreAuthorize("hasRole('ROLE_ADMIN')") public String execute() throws Exception { // do some stuff and get a chart going // DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); TimeSeriesCollection dataSet = new TimeSeriesCollection(); List<RunnerHistoryEvent> events = auditService.getSuccessEvents(module, new Date(fromDate), new Date(toDate)); Map<String, TimeSeries> serieses = new HashMap<String, TimeSeries>(); for (RunnerHistoryEvent e : events) { TimeSeries s = serieses.get(e.getMethod()); if (s == null) { s = new TimeSeries(e.getMethod()); serieses.put(e.getMethod(), s); }/*from www. j a v a 2s .c o m*/ s.addOrUpdate(new Millisecond(e.getTimeStamp()), e.getRunTime()); } for (TimeSeries s : serieses.values()) { dataSet.addSeries(s); } chart = ChartFactory.createTimeSeriesChart(module, "", "run time (ms)", dataSet, true, false, false); // .createLineChart("","","Run Time (ms)",dataSet,PlotOrientation.VERTICAL, // true,false,false); XYPlot linePlot = (XYPlot) chart.getPlot(); linePlot.setDomainGridlinesVisible(true); linePlot.setRangeGridlinesVisible(true); linePlot.setRangeGridlinePaint(Color.black); linePlot.setDomainGridlinePaint(Color.black); TextTitle subTitle = new TextTitle("Successful Executions"); subTitle.setFont(new Font("Arial", Font.ITALIC, 10)); chart.addSubtitle(subTitle); chart.getTitle().setFont(new Font("Arial", Font.BOLD, 12)); DateAxis axis = (DateAxis) linePlot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss dd-MM-yyyy")); XYItemRenderer r = linePlot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } chart.setAntiAlias(true); chart.setTextAntiAlias(true); return SUCCESS; }
From source file:com.googlecode.logVisualizer.chart.VerticalXYBarChartBuilder.java
private JFreeChart createChart(final IntervalXYDataset dataset) { final JFreeChart chart = ChartFactory.createXYBarChart(getTitle(), xLable, false, yLable, dataset, PlotOrientation.VERTICAL, isIncludeLegend(), true, false); final XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); double lastXValue = 0; if (dataset.getSeriesCount() > 0) lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1); plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue)); plot.setNoDataMessage("No data available"); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); setBarShadowVisible(chart, false);// w w w. j a va2 s . c om plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (dataset.getSeriesCount() > 0) plot.getDomainAxis().setUpperBound(lastXValue); plot.getDomainAxis().setLowerBound(0); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setUpperMargin(0.1); return chart; }
From source file:com.wattzap.view.graphs.MMPGraph.java
public MMPGraph(XYSeries series) { super();// www . j a va 2 s .c om NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt")); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); double maxY = series.getMaxY(); yAxis.setRange(0, maxY + 20); yAxis.setTickLabelPaint(Color.white); yAxis.setLabelPaint(Color.white); LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time")); xAxis.setTickLabelPaint(Color.white); xAxis.setBase(4); xAxis.setAutoRange(false); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setRange(1, series.getMaxX() + 500); xAxis.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { long millis = (long) number * 1000; if (millis >= 60000) { return new StringBuffer(String.format("%d m %d s", TimeUnit.MILLISECONDS.toMinutes((long) millis), TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } else { return new StringBuffer(String.format("%d s", TimeUnit.MILLISECONDS.toSeconds((long) millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis)))); } } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return new StringBuffer(String.format("%s", number)); } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis, new XYLineAndShapeRenderer(true, false)); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.gray); plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.darkGray); /*plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray);*/ ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setBackground(Color.gray); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); }
From source file:ec.util.chart.swing.Charts.java
@Nullable public static LegendItemEntity getSeriesForPoint(@Nonnull Point pt, @Nonnull ChartPanel cp) { final double chartX; final double chartY; final Rectangle2D plotArea; final XYPlot plot; {/*from w w w . ja v a 2 s.c o m*/ // Let's find the X and Y values of the clicked point Point2D p = cp.translateScreenToJava2D(pt); chartX = p.getX(); chartY = p.getY(); // Let's find plotArea and plot XYPlot tmpPlot = cp.getChart().getXYPlot(); PlotRenderingInfo plotInfo = cp.getChartRenderingInfo().getPlotInfo(); if (tmpPlot instanceof CombinedDomainXYPlot) { int subplotIndex = plotInfo.getSubplotIndex(p); if (subplotIndex == -1) { return null; } plotArea = plotInfo.getSubplotInfo(subplotIndex).getDataArea(); plot = ((CombinedDomainXYPlot) tmpPlot).findSubplot(plotInfo, p); } else { plotArea = plotInfo.getDataArea(); plot = tmpPlot; } } // Let's avoid unnecessary computation final ValueAxis domainAxis = plot.getDomainAxis(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final double x = domainAxis.java2DToValue(chartX, plotArea, domainAxisEdge); final double sensitivity = TOL; double distanceClickSeries = TOL + 1; Entry<XYDataset, Comparable> result = null; // For each series in each datasets for (XYDataset dataset : asDatasetList(plot)) { for (int series = 0; series < dataset.getSeriesCount(); series++) { // Index of the closest data item of the current series just left to the click int lp = getNearestLeftPoint(x, 0, dataset.getItemCount(series) - 1, series, dataset); try { // X and Y values of data items to the left and to the right double leftX = dataset.getXValue(series, lp); double leftY = dataset.getYValue(series, lp); double rightX = dataset.getXValue(series, lp + 1); double rightY = dataset.getYValue(series, lp + 1); double lx = domainAxis.valueToJava2D(leftX, plotArea, domainAxisEdge); double ly = rangeAxis.valueToJava2D(leftY, plotArea, rangeAxisEdge); double rx = domainAxis.valueToJava2D(rightX, plotArea, domainAxisEdge); double ry = rangeAxis.valueToJava2D(rightY, plotArea, rangeAxisEdge); // Distance to left point double distL = Point2D.distance(lx, ly, chartX, chartY); // Distance to right point double distR = Point2D.distance(rx, ry, chartX, chartY); // Average of both distances double distLRavg = (distL + distR) / 2d; // Distance to the segment between L and R //double distSeg = Line2D.ptSegDist(leftX, leftY, rightX, rightY, chartX, chartY); double distSeg = ptSegDist(lx, ly, rx, ry, chartX, chartY); // With a line renderer, this is probably a bit of overkill as // distSeg would be enough, but it becomes more reliable to check all these // if using splines double tmp = Math.min(Math.min(distSeg, Math.min(distL, distR)), distLRavg); // Are we closer than the previous series? if (tmp < sensitivity && tmp < distanceClickSeries) { distanceClickSeries = tmp; result = new SimpleEntry<>(dataset, dataset.getSeriesKey(series)); } } catch (Exception ex) { /* * An exception might happen when some series have less data * than others, catching the the exception here will simply rule * them out from the detection on this click */ } } } return result != null ? createFakeLegendItemEntity(result.getKey(), result.getValue()) : null; }