List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:net.sf.jdmf.visualization.clustering.ChartGenerator.java
public JFreeChart generateXYChart(List<Cluster> clusters, Integer firstAttributeIndex, String firstAttributeName, Integer secondAttributeIndex, String secondAttributeName) { XYSeriesCollection dataset = new XYSeriesCollection(); for (Cluster cluster : clusters) { XYSeries series = new XYSeries(cluster.getName()); for (Vector<Double> point : cluster.getPoints()) { series.add(point.get(firstAttributeIndex), point.get(secondAttributeIndex)); }/*from www .j ava2 s.c o m*/ dataset.addSeries(series); } XYToolTipGenerator xyToolTipGenerator = new XYToolTipGenerator() { public String generateToolTip(XYDataset dataset, int series, int item) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(String.format("<html><p style='color:#0000ff;'>Series: '%s'</p>", dataset.getSeriesKey(series))); Cluster cl = clusters.get(series); Vector<Double> point = cl.getPoints().get(item); for (int i = 0; i < point.size(); i++) { //stringBuilder.append(String.format("Attr:'%d'<br/>", d)); try { String attr = _attrName.get(i); stringBuilder.append(attr + " " + point.get(i) + "<br/>"); } catch (Exception e) { // Do nothing } } stringBuilder.append("</html>"); return stringBuilder.toString(); } }; /*** return ChartFactory.createScatterPlot( "Cluster Analysis", firstAttributeName, secondAttributeName, dataset, PlotOrientation.VERTICAL, true, true, false ); ***/ JFreeChart jfc = ChartFactory.createScatterPlot("Cluster Analysis", firstAttributeName, secondAttributeName, dataset, PlotOrientation.VERTICAL, true, true, false); XYItemRenderer render = jfc.getXYPlot().getRenderer(); render.setBaseToolTipGenerator(xyToolTipGenerator); return jfc; }
From source file:com.hazelcast.simulator.visualiser.ui.Chart.java
public Chart(Model model, AccuracyRadioButtons accuracyRadioButtons, AutoScaleRadioButtons autoScaleRadioButtons, ProbesCheckboxes probesCheckboxes) { this.model = model; this.accuracyRadioButtons = accuracyRadioButtons; this.autoScaleRadioButtons = autoScaleRadioButtons; this.probesCheckboxes = probesCheckboxes; setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); setLayout(new BorderLayout()); initSliders();/*from w w w.ja v a2s.c o m*/ JPanel horizontalSlidersPanel = new JPanel(); horizontalSlidersPanel.setLayout(new BoxLayout(horizontalSlidersPanel, BoxLayout.Y_AXIS)); horizontalSlidersPanel.add(mainHorizontalSlider); horizontalSlidersPanel.add(fineHorizontalSlider); JFreeChart chart = ChartFactory.createHistogram("Latency Distribution", "Latency (s)", "Operations", null, PlotOrientation.VERTICAL, true, true, true); plot = chart.getXYPlot(); plot.setForegroundAlpha(ALPHA); ChartPanel chartPanel = new ChartPanel(null); chartPanel.setChart(chart); add(horizontalSlidersPanel, BorderLayout.SOUTH); add(verticalSlider, BorderLayout.EAST); add(chartPanel, BorderLayout.CENTER); initSliderChangeListener(); }
From source file:net.sf.mzmine.chartbasics.chartthemes.EStandardChartTheme.java
@Override public void apply(JFreeChart chart) { // TODO Auto-generated method stub super.apply(chart); ////w w w . j a v a 2 s .c o m chart.getXYPlot().setDomainGridlinesVisible(showXGrid); chart.getXYPlot().setRangeGridlinesVisible(showYGrid); // all axes for (int i = 0; i < chart.getXYPlot().getDomainAxisCount(); i++) { NumberAxis a = (NumberAxis) chart.getXYPlot().getDomainAxis(i); a.setTickMarkPaint(axisLinePaint); a.setAxisLinePaint(axisLinePaint); // visible? a.setVisible(showXAxis); } for (int i = 0; i < chart.getXYPlot().getRangeAxisCount(); i++) { NumberAxis a = (NumberAxis) chart.getXYPlot().getRangeAxis(i); a.setTickMarkPaint(axisLinePaint); a.setAxisLinePaint(axisLinePaint); // visible? a.setVisible(showYAxis); } // apply bg chart.setBackgroundPaint(this.getChartBackgroundPaint()); chart.getPlot().setBackgroundPaint(this.getPlotBackgroundPaint()); for (int i = 0; i < chart.getSubtitleCount(); i++) { // visible? chart.getSubtitle(i).setVisible(subtitleVisible); // if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(this.getChartBackgroundPaint()); } if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(this.getChartBackgroundPaint()); // chart.setAntiAlias(isAntiAliased()); chart.getTitle().setVisible(isShowTitle()); chart.getPlot().setBackgroundAlpha(isNoBackground() ? 0 : 1); }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title./* ww w .j a va 2 s .c om*/ */ public SecondaryDatasetDemo1(String title) { super(title); TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); JFreeChart chart = ChartFactory.createTimeSeriesChart("Secondary Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:gda.plots.DataMagnifierWindow.java
/** * Sets the SimplePlot to be magnified.//ww w .j a va2 s . co m * * @param simplePlot * the SimplePlot which the magnifier will be Magnifying * @param collection */ @Override public void setSimplePlot(SimplePlot simplePlot, XYSeriesCollection collection) { this.simplePlot = simplePlot; setTitle("Data Magnifier"); // The magnifiedPlot is effectively just another view of the data of the // simplePlot. By creating a JFreeChart and extracting its plot we get // all // the tediouse work done elsewhere. JFreeChart magnifiedChart = ChartFactory.createXYLineChart(simplePlot.getTitle(), null, null, collection, PlotOrientation.VERTICAL, false, false, false); magnifiedChart.setAntiAlias(false); magnifiedPlot = magnifiedChart.getXYPlot(); magnifiedPlot.setRenderer(simplePlot.getChart().getXYPlot().getRenderer()); if (simplePlot.isShowToolTip()) magnifiedPlot.getRenderer().setToolTipGenerator(new SimpleXYToolTipGenerator()); add(new DataMagnifierPanel()); }
From source file:org.vrjuggler.perfmon.PerformanceMonitorGUI.java
private JFreeChart createTimeSeriesChart(TimeSeriesCollection dataset) { JFreeChart result = ChartFactory.createTimeSeriesChart("Performance Monitoring Statistics", "Time", "Sample", dataset, true, true, false); XYPlot plot = result.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true);/*w w w.j a v a 2 s . com*/ axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setAutoRange(true); //axis.setRange( 0.0, 10.0 ); return result; }
From source file:org.webcat.grader.graphs.StackedAreaChart.java
@Override protected JFreeChart generateChart(WCChartTheme chartTheme) { JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, xAxisLabel(), yAxisLabel(), tableXYDataset(), orientation(), true, false, false); XYPlot plot = chart.getXYPlot(); long diff = (long) tableXYDataset().getXValue(0, tableXYDataset().getItemCount() - 1) - (long) tableXYDataset().getXValue(0, 0); GregorianCalendar calDiff = new GregorianCalendar(); calDiff.setTime(new NSTimestamp(diff)); // Set the time axis PeriodAxis axis = new PeriodAxis(null); // ( "Date" ); PeriodAxisLabelInfo labelinfo[] = new PeriodAxisLabelInfo[2]; if (calDiff.get(Calendar.DAY_OF_YEAR) > 1) { axis.setTimeZone(TimeZone.getTimeZone(user().timeZoneName())); axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class); axis.setMajorTickTimePeriodClass(org.jfree.data.time.Week.class); labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); } else {//from w w w . jav a 2s. co m axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Hour.class); labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("ha"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM-d"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); } axis.setLabelInfo(labelinfo); plot.setDomainAxis(axis); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); NumberTickUnit tickUnit = new NumberTickUnit(5); rangeAxis.setTickUnit(tickUnit); XYAreaRenderer2 renderer = (XYAreaRenderer2) plot.getRenderer(); renderer.setOutline(true); renderer.setAutoPopulateSeriesOutlinePaint(true); plot.setDomainMinorGridlinesVisible(false); plot.setRangeMinorGridlinesVisible(false); if (markValue != null) { plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairValue(markValue.doubleValue()); plot.setDomainCrosshairPaint(Color.red); plot.setDomainCrosshairStroke(MARKER_STROKE); } chart.getLegend().setBorder(0, 0, 0, 0); return chart; }
From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w ww. ja v a 2 s . c o m */ public MultipleDatasetDemo1(final String title) { super(title); final TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:edu.cmu.sv.modelinference.eventtool.EventVisualizer.java
private void visualizeClasses(ClassificationResult classes, Map<EventClass, Color> clusterColors) { DataChart clustersDataChart = new DataChart("Classification chart"); JFreeChart clusterChart = clustersDataChart.chart(""); XYPlot clusterPlot = clusterChart.getXYPlot(); int dataSetIndex = 0; Map<Integer, EventClass> dataSetIdx2EvtClass = new HashMap<>(); //ugly DefaultXYDataset eventDataSet = new DefaultXYDataset(); for (EventClass evtCl : classes.getEventClasses()) { double[][] clusterDataSet = new double[][] { new double[evtCl.getEvents().size()], new double[evtCl.getEvents().size()] }; int i = 0; for (Event data : evtCl.getEvents()) { clusterDataSet[0][i] = 0;/*from w w w .ja v a 2s. c o m*/ clusterDataSet[1][i] = data.getFeature().getData(); i++; } eventDataSet.addSeries("Class " + evtCl.getClassId(), clusterDataSet); dataSetIdx2EvtClass.put(dataSetIndex, evtCl); dataSetIndex++; } clusterPlot.setDataset(eventDataSet); for (Entry<Integer, EventClass> ent : dataSetIdx2EvtClass.entrySet()) { int idx = ent.getKey(); Color clr = clusterColors.get(ent.getValue()); logger.info("Setting color " + clr + " for event class " + ent.getValue().getClassId() + " with index " + idx); clusterPlot.getRendererForDataset(clusterPlot.getDataset(0)).setSeriesPaint(idx, clr); } clustersDataChart.pack(); RefineryUtilities.centerFrameOnScreen(clustersDataChart); clustersDataChart.setVisible(true); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.ScatterPlotChartExpression.java
protected JFreeChart computeXYChart(final XYDataset xyDataset) { final JFreeChart chart; if (xyDataset instanceof TimeSeriesCollection) { chart = ChartFactory.createTimeSeriesChart(computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, isShowLegend(), false, false); final XYPlot xyPlot = chart.getXYPlot(); final XYLineAndShapeRenderer itemRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(itemRenderer.getBaseToolTipGenerator()); renderer.setURLGenerator(itemRenderer.getURLGenerator()); xyPlot.setRenderer(renderer);//ww w . j a va 2 s . co m } else { final PlotOrientation orientation = computePlotOrientation(); chart = ChartFactory.createScatterPlot(computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, orientation, isShowLegend(), false, false); } chart.getXYPlot().setRenderer(new XYDotRenderer()); configureLogarithmicAxis(chart.getXYPlot()); return chart; }