List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
private void recalcScrollBar(Plot plot) { if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot; ValueAxis axis = hvp.getDomainAxis(); axis.setLowerMargin(0);/*from w w w.j a v a 2s . c o m*/ axis.setUpperMargin(0); Range rng = axis.getRange(); BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel(); int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum(); if (rng.getLength() > 0) { scrollFactor = len / rng.getLength(); } double dblow = rng.getLowerBound(); int ilow = (int) (dblow * scrollFactor); scrollBarModel.setMinimum(ilow); int val = ilow; scrollBarModel.setValue(val); double dbup = rng.getUpperBound(); int iup = (int) (dbup * scrollFactor); scrollBarModel.setMaximum(iup); int ext = iup - ilow; scrollBarModel.setExtent(ext); scrollBarModel.addChangeListener(this); } }
From source file:edu.utexas.ece.pharos.proteus3.sensors.CompassChartGUI.java
/** * Creates a chart.// ww w . j a v a 2 s . c om * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart("Proteus III Compass Measurements", // chart title "Time (s)", // x axis label "Angle (degrees)", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customization... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setRange(new Range(0, 140)); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); // change the auto tick unit selection to integer units only... // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //rangeAxis.setRange(new Range(-Math.PI, Math.PI)); rangeAxis.setRange(new Range(-180, 180)); return chart; }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void stateChanged(ChangeEvent event) { try {// www . j a v a 2 s . co m Object src = event.getSource(); BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel(); if (src == scrollBarModel) { int val = scrollBarModel.getValue(); int ext = scrollBarModel.getExtent(); Plot plot = this.chartPanel.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot; ValueAxis axis = hvp.getDomainAxis(); // avoid problems this.chartPanel.getChart().removeChangeListener(this); axis.setRange(val / scrollFactor, (val + ext) / scrollFactor); // restore chart listener this.chartPanel.getChart().addChangeListener(this); } } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.ClinicalPlot.java
private void createChart() { //String xLabel = factor1.toString(); String xLabel = factor1AxisLabel; //String yLabel = factor2.toString(); String yLabel = factor2AxisLabel; clinicalChart = ChartFactory.createScatterPlot("Clinical Plot", xLabel, yLabel, null, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) clinicalChart.getPlot(); buildLegend();// www .j a v a 2s. co m plot.setNoDataMessage(null); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setUseOutlinePaint(true); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairVisible(false); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); //should determine axis range using datapoints. domainAxis.setAutoRangeIncludesZero(false); //get domain and range of the axis. DataRange domainAxisLimits = getDataRange(dataPoints, factor1, true); DataRange rangeAxisLimits = getDataRange(dataPoints, factor2, true); //domainAxis.setRange(domainAxisLimits.getMinRange(), domainAxisLimits.getMaxRange()); //rangeAxis.setRange(rangeAxisLimits.getMinRange(), rangeAxisLimits.getMaxRange()); double domainMax = Math.max(100.0, domainAxisLimits.getMaxRange()) + 5.0; double rangeMax = Math.max(100.0, rangeAxisLimits.getMaxRange()) + 5.0; domainAxis.setRange(0.0, domainMax); rangeAxis.setRange(0.0, rangeMax); System.out.println("domainAxis=" + domainAxis.getLabel()); System.out.println("rangeAxis=" + rangeAxis.getLabel()); createGlyphsAndAddToPlot(plot); }
From source file:com.ivli.roim.controls.ChartControl.java
private ValueMarker findMarker(MouseEvent e) { final XYPlot plot = getChart().getXYPlot(); Collection mark = plot.getDomainMarkers(Layer.FOREGROUND); if (null == mark || mark.isEmpty()) return null; final double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(), plot.getDomainAxisEdge());//from w w w . j av a 2 s.c om final double Epsilon = plot.getDataRange(plot.getDomainAxis()).getLength() * .01d; for (Object o : mark) { if (o instanceof DomainMarker) { //DomainMarker m = (DomainMarker)o; double val = ((DomainMarker) o).getValue(); if (val >= domainX - Epsilon && val <= domainX + Epsilon) { //getContentPane().setCursor(new Cursor(Cursor.HAND_CURSOR)); return (ValueMarker) o; } } } return null; }
From source file:com.view.TimeSeriesChartView.java
public JFreeChart getVendorTimeSeriesChart(Excel theExcel, String vendor) { int vendorCode = Integer.parseInt(vendor); ArrayList<Receiving> theReceiving = theExcel.getSheetReceiving(); // HashMap<Month, Integer> item1Map = new HashMap<>(); // HashMap<Month, Integer> item2Map = new HashMap<>(); // HashMap<Month, Integer> item3Map = new HashMap<>(); Set vendorItem = new HashSet(); for (int i = 0; i < theReceiving.size(); i++) { vendorItem.add(theReceiving.get(i).getItem()); }/* w ww .j a v a2 s.com*/ TimeSeries data[] = new TimeSeries[vendorItem.size()]; HashMap<Month, Integer> itemMap[] = new HashMap[vendorItem.size()]; for (int i = 0; i < vendorItem.size(); i++) { String itemName = "item" + i; data[i] = new TimeSeries(itemName); itemMap[i] = new HashMap<>(); } Calendar cal = Calendar.getInstance(); for (int i = 0; i < theReceiving.size(); i++) { cal.setTime(theReceiving.get(i).getDate()); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int quantity = 0; if (theReceiving.get(i).getVendor() == vendorCode) { quantity = theReceiving.get(i).getQuantity(); Month theMonth = new Month(month, year); int itemNum = theReceiving.get(i).getItem() - 1; itemMap[itemNum].put(theMonth, updateItemMap(itemMap[itemNum], theMonth, quantity)); } } TimeSeriesCollection my_data_series = new TimeSeriesCollection(); for (int i = 0; i < vendorItem.size(); i++) { for (Map.Entry<Month, Integer> entry : itemMap[i].entrySet()) { data[i].add(entry.getKey(), entry.getValue()); } my_data_series.addSeries(data[i]); } JFreeChart chart = ChartFactory.createTimeSeriesChart("Receiving", "Month", "Quantity", my_data_series, true, true, false); chart.setBackgroundPaint(Color.YELLOW); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.GREEN); plot.setRangeGridlinePaint(Color.orange); plot.setAxisOffset(new RectangleInsets(50, 0, 20, 5)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MM.yyyy")); return chart; }
From source file:fi.smaa.jsmaa.gui.views.CriterionView.java
private JPanel buildValueFunctionChartPanel(ScaleCriterion criterion) { UtilityFunctionDataset dataset = new UtilityFunctionDataset(criterion); JFreeChart chart = ChartFactory.createXYLineChart("", "x", "v(x)", dataset, PlotOrientation.VERTICAL, false, true, true);/*www . j av a 2 s . c om*/ final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(0, renderer); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3.0f)); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); ValueAxis rAxis = plot.getRangeAxis(); rAxis.setAutoRange(false); rAxis.setRange(new Range(-0.03, 1.03)); ValueAxis dAxis = plot.getDomainAxis(); dAxis.setLowerMargin(0.03); dAxis.setUpperMargin(0.03); ChartPanel chartPanel = new ChartPanel(chart, false, true, true, false, true); chartPanel.addChartMouseListener(new ValueFunctionMouseListener(chartPanel, criterion, parent)); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); chartPanel.setDisplayToolTips(true); chartPanel.setToolTipText("Click to add/remove partial value function points"); chartPanel.setMouseWheelEnabled(false); chartPanel.setMouseZoomable(false); plot.setDomainCrosshairLockedOnData(false); plot.setRangeCrosshairLockedOnData(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); FormLayout layout = new FormLayout("left:pref", "p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(chartPanel, cc.xy(1, 1)); builder.add(new ValueFunctionPointsPanel(criterion), cc.xy(1, 3)); return builder.getPanel(); }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Sets the current {@link PlotConfiguration} for this dialog. * /*from ww w .j a va2s. c o m*/ * @param plotConfig */ private void setPlotConfiguration(PlotConfiguration plotConfig) { if (plotConfig == null) { throw new IllegalArgumentException("plotConfig must not be null!"); } this.plotConfig = plotConfig; Vector<RangeAxisConfig> rangeConfigsVector = new Vector<RangeAxisConfig>(); String selectedItem = String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()); for (RangeAxisConfig config : this.plotConfig.getRangeAxisConfigs()) { rangeConfigsVector.add(config); } rangeAxisSelectionCombobox.setModel(new DefaultComboBoxModel(rangeConfigsVector)); // reselect the previously selected RangeAxisConfig (if it is still there) if (selectedItem != null) { for (int i = 0; i < rangeAxisSelectionCombobox.getItemCount(); i++) { if (String.valueOf(rangeAxisSelectionCombobox.getItemAt(i)).equals(selectedItem)) { rangeAxisSelectionCombobox.setSelectedIndex(i); break; } } } // calculate preselected x/y values if (mousePosition != null) { Rectangle2D plotArea = engine.getChartPanel().getScreenDataArea(); if (engine.getChartPanel().getChart().getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) engine.getChartPanel().getChart().getPlot(); // calculate x value double chartX = plot.getDomainAxis().java2DToValue(mousePosition.getX(), plotArea, plot.getDomainAxisEdge()); xField.setText(String.valueOf(chartX)); // calculate y value for (int i = 0; i < plot.getRangeAxisCount(); i++) { ValueAxis config = plot.getRangeAxis(i); if (config != null && config.getLabel() != null) { if (config.getLabel() .equals(String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()))) { double chartY = config.java2DToValue(mousePosition.getY(), plotArea, plot.getRangeAxisEdge()); yField.setText(String.valueOf(chartY)); } } } } } }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo3.java
protected JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, true, rangeLabel, dataset, PlotOrientation.VERTICAL, false, // !legendPanelOn, true, false);/*from w w w. ja v a 2 s . c om*/ // then customise it a little... // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do")); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer(new ClusteredXYBarRenderer()); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0")); renderer.setBaseToolTipGenerator(generator); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setLowerMargin(0.01); axis.setUpperMargin(0.01); // setXSummary(dataset); X is time return chart; }
From source file:ch.unibe.iam.scg.archie.ui.charts.ConsultationNumberChart.java
/** * @see ch.unibe.iam.scg.archie.ui.charts.AbstractChartComposite# * initializeChart()//from w w w. j ava 2 s . c o m */ @Override protected JFreeChart initializeChart() { JFreeChart chart = ChartFactory.createTimeSeriesChart(ConsultationNumberChart.CHART_TITLE, // title "", // x-axis label "Count", // y-axis label (XYDataset) this.creator.getDataset(), // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(new Color(this.parent.getBackground().getRed(), this.parent.getBackground().getGreen(), this.parent.getBackground().getBlue())); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }