List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:org.jfree.chart.demo.XYTickLabelDemo.java
/** * When a checkbox is changed ...//from w w w. j a v a2 s . c om * * @param event the event. */ public void actionPerformed(final ActionEvent event) { final ValueAxis[] axes = new ValueAxis[4]; final XYPlot plot = this.chart.getXYPlot(); axes[0] = plot.getDomainAxis(); axes[1] = plot.getRangeAxis(); axes[2] = plot.getDomainAxis(1); axes[3] = plot.getRangeAxis(1); final Object source = event.getSource(); if (source == this.symbolicAxesCheckBox) { final boolean val = this.symbolicAxesCheckBox.isSelected(); for (int i = 0; i < axes.length; i++) { ValueAxis axis = axes[i]; final String label = axis.getLabel(); final int maxTick = (int) axis.getUpperBound(); final String[] tickLabels = new String[maxTick]; final Font ft = axis.getTickLabelFont(); for (int itk = 0; itk < maxTick; itk++) { tickLabels[itk] = "Label " + itk; } axis = val ? new SymbolicAxis(label, tickLabels) : new NumberAxis(label); axis.setTickLabelFont(ft); axes[i] = axis; } plot.setDomainAxis(axes[0]); plot.setRangeAxis(axes[1]); plot.setDomainAxis(1, axes[2]); plot.setRangeAxis(1, axes[3]); } if (source == this.symbolicAxesCheckBox || source == this.verticalTickLabelsCheckBox) { final boolean val = this.verticalTickLabelsCheckBox.isSelected(); for (int i = 0; i < axes.length; i++) { axes[i].setVerticalTickLabels(val); } } else if (source == this.symbolicAxesCheckBox || source == this.horizontalPlotCheckBox) { final PlotOrientation val = this.horizontalPlotCheckBox.isSelected() ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL; this.chart.getXYPlot().setOrientation(val); } else if (source == this.symbolicAxesCheckBox || source == this.fontSizeTextField) { final String s = this.fontSizeTextField.getText(); if (s.length() > 0) { final float sz = Float.parseFloat(s); for (int i = 0; i < axes.length; i++) { final ValueAxis axis = axes[i]; Font ft = axis.getTickLabelFont(); ft = ft.deriveFont(sz); axis.setTickLabelFont(ft); } } } }
From source file:de.hs.mannheim.modUro.reader.JCellCountDiagram.java
protected JFreeChart createChart(XYDataset dataset, List<String> cellTypes) { String title = "Cell count"; JFreeChart xyLineChart = ChartFactory.createXYLineChart(title, // title "t", // x-axis label "n", // y-axis label dataset);//from ww w. j ava 2s. c o m String fontName = "Palatino"; xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); XYPlot plot = (XYPlot) xyLineChart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLowerMargin(0.0); // plot.getRangeAxis().setRange(0.0, 1.01); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); xyLineChart.getLegend().setFrame(BlockBorder.NONE); xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); // set the default stroke for all series int i = 0; for (String celltype : cellTypes) { r.setSeriesPaint(i, CellTypeColor.getColor(celltype)); i++; } r.setSeriesPaint(i, Color.BLACK); return xyLineChart; }
From source file:se.lnu.cs.doris.metrics.SLOC.java
private void generateImage(ImageType type) throws Exception { if (this.m_mainDir == null) { throw new Exception("Base directory not set."); }//from w w w. j ava 2 s. c om XYSeries linesOfCodeTotal = new XYSeries("Total lines"); XYSeries linesOfCode = new XYSeries("Lines of code"); XYSeries linesOfComments = new XYSeries("Lines of comments"); XYSeries baseLine = new XYSeries("index 100"); for (File f : this.m_mainDir.listFiles()) { if (f.isDirectory() && !f.getName().contains(this.m_avoid)) { int commitNumber = Utilities.parseInt(f.getName()); int slocd = 0; int slocmt = 0; int sloct = 0; for (File sd : f.listFiles()) { if (!sd.getName().toLowerCase().contains(this.m_avoid)) { slocd += this.countLines(sd, false); slocmt += this.countLines(sd, true); sloct += slocd + slocmt; } } if (this.m_baseValueTotal < 0) { this.m_baseValueTotal = sloct; this.m_baseValueComments = slocmt; this.m_baseValueCode = slocd; sloct = 100; slocmt = 100; slocd = 100; } else { sloct = (int) ((double) sloct / (double) this.m_baseValueTotal * 100); slocmt = (int) ((double) slocmt / (double) this.m_baseValueComments * 100); slocd = (int) ((double) slocd / (double) this.m_baseValueCode * 100); } linesOfCodeTotal.add(commitNumber, sloct); linesOfCode.add(commitNumber, slocd); linesOfComments.add(commitNumber, slocmt); baseLine.add(commitNumber, 100); } } XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(linesOfCodeTotal); collection.addSeries(linesOfCode); collection.addSeries(linesOfComments); collection.addSeries(baseLine); JFreeChart chart = ChartFactory.createXYLineChart( "Source lines of code change for " + this.m_projectName + " \nBase value code: " + this.m_baseValueCode + "\nBase value comments: " + this.m_baseValueComments, "Commit", "SLOC change %", collection, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setTickUnit(new NumberTickUnit(2)); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setTickUnit(new NumberTickUnit(10)); switch (type) { case JPEG: ChartUtilities.saveChartAsJPEG(new File(this.m_mainDir.getAbsolutePath(), "sloc_chart.jpg"), chart, 1000, 720); break; case PNG: ChartUtilities.saveChartAsPNG(new File(this.m_mainDir.getAbsolutePath(), "sloc_chart.png"), chart, 1000, 720); break; default: break; } }
From source file:MouseEventListener.java
@Override public void chartMouseMoved(ChartMouseEvent arg0) { Double chartX;/*from w w w . java 2 s.c om*/ Double chartT; XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); chartX = plot.getRangeAxis().java2DToValue( chartPanel.translateScreenToJava2D(arg0.getTrigger().getPoint()).getY(), chartPanel.getScreenDataArea(), plot.getRangeAxisEdge()); chartT = plot.getDomainAxis().java2DToValue( chartPanel.translateScreenToJava2D(arg0.getTrigger().getPoint()).getX(), chartPanel.getScreenDataArea(), plot.getDomainAxisEdge()); //simuladorGUI.actualizarPosicionCursor(chartX, chartT); }
From source file:org.n52.io.measurement.img.ChartIoHandler.java
private void configureTimeAxis(XYPlot xyPlot) { DateAxis timeAxis = (DateAxis) xyPlot.getDomainAxis(); timeAxis.setRange(getStartTime(getTimespan()), getEndTime(getTimespan())); String timeformat = "yyyy-MM-dd, HH:mm"; if (getChartStyleDefinitions().containsParameter("timeformat")) { timeformat = getChartStyleDefinitions().getAsString("timeformat"); }/*w ww. ja v a 2s.c o m*/ DateFormat requestTimeFormat = new SimpleDateFormat(timeformat, i18n.getLocale()); requestTimeFormat.setTimeZone(getTimezone().toTimeZone()); timeAxis.setDateFormatOverride(requestTimeFormat); timeAxis.setTimeZone(getTimezone().toTimeZone()); }
From source file:D1WaveletTransform.java
@Test public void test() throws InterruptedException, JWaveException { CategoryTableXYDataset serie = new CategoryTableXYDataset(); serie.setNotify(false);// www. ja v a 2s.c o m double step = 1.0 / discretization; double startPosition = step * framePosition; //100 ? - 100 , 50 ? - 50 , 25 ?- 25 WaveletTransform t = new FastWaveletTransform((new Haar1())); double[] data = t.forward(testData.get1DSimpleSignal(1, 3, frameWidth, discretization), 128); // double[] data = math.convolve(testData.get1DSignal(100, 200, frameWidth, discretization), math.lpf(70, step, 128)); // double[] data = math.convolve(testData.get1DSignal(100, 200, 32768, 10000), math.lpf(70, 1./10000, 32)); // double[] data = testData.get1DSignal(100, 200, frameWidth, discretization); // double[] data = math.lpf(70, step,128); for (int i = 0; i < data.length; i++) { serie.add(startPosition, data[i], ""); startPosition += step; } JFreeChart chart = ChartFactory.createXYLineChart("", "t,c", "wave", serie); chart.removeLegend(); chart.setAntiAlias(false); XYPlot plot = chart.getXYPlot(); //plot.setRangeGridlinePaint(Color.BLACK); org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis(); org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis(); double start = framePosition * 1.0 / discretization; double max = start + frameWidth * 1.0 / discretization; xAxis.setRange(start, max); ChartPanel chartPanel = new ChartPanel(chart); JPanel p = new JPanel(new BorderLayout()); p.removeAll(); p.add(chartPanel); p.validate(); //1. Create the frame. JFrame frame = new JFrame("FrameDemo"); //2. Optional: What happens when the frame closes? frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //3. Create components and put them in the frame. //...create emptyLabel... frame.getContentPane().add(new Label("olol"), BorderLayout.CENTER); frame.getContentPane().add(p, BorderLayout.CENTER); //4. Size the frame. frame.pack(); //5. Show it. frame.setVisible(true); }
From source file:com.charts.IntradayChart.java
public IntradayChart(YStockQuote currentStock) { TimeSeries series = new TimeSeries(currentStock.get_name()); ArrayList<String> fiveDayData = currentStock.get_one_day_data(); int length = fiveDayData.size(); for (int i = 17; i < length; i++) { String[] data = fiveDayData.get(i).split(","); Date time = new Date((long) Integer.parseInt(data[0]) * 1000); DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m"); series.addOrUpdate(new Minute(time), Double.parseDouble(data[1])); }/* w w w . j a v a 2 s . com*/ TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart( currentStock.get_name() + "(" + currentStock.get_symbol() + ")" + " Intraday", "Date", "Price", dataset, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); xAxis.setDateFormatOverride(new SimpleDateFormat("h:m a")); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //xAxis.setVerticalTickLabels(true); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(chartPanel.getBackground()); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:org.easyrec.controller.StatisticsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { if (Security.isSignedIn(request)) { int tenant; int month; int year; boolean flot; String actionType = request.getParameter("actionType"); try {/*from w ww.j a v a 2 s .c o m*/ tenant = Integer.parseInt(request.getParameter("tenant")); month = Integer.parseInt(request.getParameter("month")); year = Integer.parseInt(request.getParameter("year")); flot = Integer.parseInt(request.getParameter("flot")) != 0; } catch (Exception e) { logger.warn(e); return null; } ModelAndView mav = new ModelAndView(); XYSeriesCollection dataset = new XYSeriesCollection(); FlotDataSet flotDataSet = new FlotDataSet(); Calendar from = Calendar.getInstance(); Calendar to = Calendar.getInstance(); from.set(year, month, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH), 0, 0, 0); to.set(year, month, from.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); Integer actionTypeId = null; Integer assocTypeId = null; if (!Strings.isNullOrEmpty(actionType)) { if ("CLICKS_ON_RECS".equals(actionType)) assocTypeId = 1001; else if ("CLICKS_ON_CHARTS".equals(actionType)) assocTypeId = 998; else actionTypeId = typeMappingService.getIdOfActionType(tenant, actionType); } HashMap<Integer, HashMap<Integer, Integer>> actionBundleMap = statisticsDAO.getActionBundleMap(tenant, from.getTimeInMillis(), to.getTimeInMillis(), actionTypeId, assocTypeId); Iterator<Integer> iterator = actionBundleMap.keySet().iterator(); while (iterator.hasNext()) { actionTypeId = iterator.next(); if (actionTypeId == 1001) actionType = "clicks on recommendations"; else if (actionTypeId == 998) actionType = "clicks on rankings"; else actionType = typeMappingService.getActionTypeById(tenant, actionTypeId).toLowerCase() + " actions"; XYSeries xySeries = new XYSeries(actionType); FlotSeries flotSeries = new FlotSeries(); flotSeries.setTitle(actionType); for (int i = 1; i <= 31; i++) { Integer y = actionBundleMap.get(actionTypeId).get(i); xySeries.add(i, y != null ? y : 0); flotSeries.add(i, y != null ? y : 0); } //mav.addObject("data",flotDataSet.toString()); dataset.addSeries(xySeries); flotDataSet.add(flotSeries); } // create datapoints that are rendered in the clients browser // return array or html side that renders array if (flot) { boolean onlyData = (ServletUtils.getSafeParameter(request, "onlyData", 0) != 0); if (onlyData) { mav.setViewName("flot/dataOutput"); } else { mav.setViewName("flot/flotPlot"); } mav.addObject("data", flotDataSet.toString()); mav.addObject("flotDataSet", flotDataSet.getData()); mav.addObject("noActions", flotDataSet.getData().isEmpty()); return mav; // create a png } else { JFreeChart action_chart = ChartFactory.createXYLineChart("", "actions", "days", dataset, PlotOrientation.VERTICAL, true, // show legend true, // show tooltips false); // show urls XYPlot plot = action_chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setRange(1, 31); plot.setDomainAxis(axis); BufferedImage bi = action_chart.createBufferedImage(300, 200); byte[] bytes = ChartUtilities.encodeAsPNG(bi); if (bytes != null & !flot) { OutputStream os = response.getOutputStream(); response.setContentType("image/png"); response.setContentLength(bytes.length); os.write(bytes); os.close(); } } return null; } else { return Security.redirectHome(request, response); } }
From source file:fungus.PeerRatioChartFrame.java
public PeerRatioChartFrame(String prefix) { simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES); this.setTitle("MycoNet Statistics Chart"); graph = JungGraphObserver.getGraph(); //data.add(-1,0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.setAutoWidth(false);// w w w. java2 s . c om dataset.setIntervalWidth(simulationCycles); //averageUtilizationData = new XYSeries("Average Utilization"); //dataset.addSeries(averageUtilizationData); //averageStableUtilizationData = new XYSeries("Avg Stable Util"); //dataset.addSeries(averageStableUtilizationData); bulwarkRatioData = new XYSeries("Bulwark Ratio"); dataset.addSeries(bulwarkRatioData); biomassRatioData = new XYSeries("Biomass Ratio"); dataset.addSeries(biomassRatioData); hyphaRatioData = new XYSeries("Hypha Ratio"); dataset.addSeries(hyphaRatioData); // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio"); // dataset.addSeries(stableHyphaRatioData); //XYSeriesCollection dataset; JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio", dataset, PlotOrientation.VERTICAL, true, false, false); ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart); XYPlot xyplot = peerRatioChart.getXYPlot(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(0, 1); //chart.setBackgroundPaint(Color.white); //XYPlot plot = chart.getXYPlot(); // BufferedImage chartImage = chart.createBufferedImage(500,300); // chartLabel = new JLabel(); //chartLabel.setIcon(new ImageIcon(chartImage)); Container contentPane = getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); JPanel labelPane = new JPanel(); labelPane.setLayout(new GridLayout(1, 1)); //chartPane.setPreferredSize(new java.awt.Dimension(500, 300)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); ////contentPane.add(labelPane,BorderLayout.PAGE_START); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); contentPane.add(peerRatioChartPanel, BorderLayout.CENTER); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); ////contentPane.add(buttonPane, BorderLayout.PAGE_END); //data = node.getHyphaData(); //link = node.getHyphaLink(); //mycocast = node.getMycoCast(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //chartPanel.add(chartLabel); /*JButton updateButton = new JButton("Refresh"); ActionListener updater = new ActionListener() { public void actionPerformed(ActionEvent e) { refreshData(); } }; updateButton.addActionListener(updater); JButton closeButton = new JButton("Close"); ActionListener closer = new ActionListener() { public void actionPerformed(ActionEvent e) { closeFrame(); } }; closeButton.addActionListener(closer); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(updateButton); buttonPane.add(Box.createRigidArea(new Dimension(5,0))); buttonPane.add(closeButton); refreshData(); */ //JungGraphObserver.addChangeListener(this); this.pack(); this.setVisible(true); }
From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java
private JFreeChart createXYLineChart(LoggerData loggerData, XYDataset dataset, boolean combined) { String title = combined ? "Combined Data" : loggerData.getName(); String rangeAxisTitle = combined ? "Data" : buildRangeAxisTitle(loggerData); JFreeChart chart = ChartFactory.createXYLineChart(title, "Time (sec)", rangeAxisTitle, dataset, VERTICAL, false, true, false);//from w w w. jav a2s . c o m chart.setBackgroundPaint(BLACK); chart.getTitle().setPaint(WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(BLACK); plot.getDomainAxis().setLabelPaint(WHITE); plot.getRangeAxis().setLabelPaint(WHITE); plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY); plot.getRangeAxis().setTickLabelPaint(LIGHT_GREY); plot.setDomainGridlinePaint(DARK_GREY); plot.setRangeGridlinePaint(DARK_GREY); plot.setOutlinePaint(DARK_GREY); return chart; }