Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart JFreeChart.

Prototype

public JFreeChart(Plot plot) 

Source Link

Document

Creates a new chart based on the supplied plot.

Usage

From source file:inflor.core.plots.CategoryResponseChart.java

public JFreeChart createChart(FCSFrame dataFrame) {

    CategoryXYZDataSet categoryData = new CategoryXYZDataSet();
    double zMin = Double.MAX_VALUE;
    double zMax = 1;
    if (dataFrame.getKeywords().containsKey(FCSUtilities.KEY_MERGE_MAP)) {
        String[] mergeMap = dataFrame.getKeywordValue(FCSUtilities.KEY_MERGE_MAP)
                .split(NodeUtilities.DELIMITER_REGEX);
        FCSDimension dim = dataFrame.getDimension(axisName);
        double[] transformedData = transform.transform(dim.getData());
        int perFileSize = dim.getData().length / mergeMap.length;
        for (int i = 0; i < mergeMap.length; i++) {

            double[] unMergedData = new double[perFileSize];
            for (int j = 0; j < unMergedData.length; j++) {
                unMergedData[j] = transformedData[i * unMergedData.length + j];
            }/*from ww  w.ja v  a 2  s.  com*/
            double tMin = transform.getMinTranformedValue();
            double tMax = transform.getMaxTransformedValue();
            Histogram1D hist = new Histogram1D(unMergedData, tMin, tMax, ChartingDefaults.BIN_COUNT);
            double[] x = hist.getNonZeroX();
            double[] y = new double[x.length];
            for (int j = 0; j < y.length; j++) {
                y[j] = i;
            }
            double[] z = hist.getNonZeroY();
            double currentZMin = Doubles.min(z);
            double currentZMax = Doubles.max(z);
            if (currentZMin < zMin) {
                zMin = currentZMin;
            } else if (currentZMax > zMax) {
                zMax = currentZMax;
            }

            categoryData.addCategoricalSeries(mergeMap[i], x, z);
        }
    } else {
        FCSDimension dim = dataFrame.getDimension(axisName);
        double[] transformedData = transform.transform(dim.getData());
        Histogram1D hist = new Histogram1D(transformedData, transform.getMinTranformedValue(),
                transform.getMaxTransformedValue(), ChartingDefaults.BIN_COUNT);
        double[] x = hist.getNonZeroX();
        double[] y = new double[x.length];
        for (int j = 0; j < y.length; j++) {
            y[j] = 0;
        }
        double[] z = hist.getNonZeroY();
        double currentZMin = Doubles.min(z);
        double currentZMax = Doubles.max(z);
        if (currentZMin < zMin) {
            zMin = currentZMin;
        } else if (currentZMax > zMax) {
            zMax = currentZMax;
        }

        categoryData.addCategoricalSeries(dataFrame.getDisplayName(), x, z);
    }

    ValueAxis domainAxis = PlotUtils.createAxis(axisName, transform);
    NumberAxis rangeAxis = new CategoricalNumberAxis("", categoryData.getLabelMap());
    // Renderer configuration
    XYBlockRenderer renderer = new XYBlockRenderer();
    double xWidth = (transform.getMaxTransformedValue() - transform.getMinTranformedValue())
            / ChartingDefaults.BIN_COUNT;
    renderer.setBlockWidth(xWidth);
    renderer.setBlockHeight(0.5);
    renderer.setBlockAnchor(RectangleAnchor.LEFT);

    PaintScale paintScale = PlotUtils.createPaintScale(zMax, ChartingDefaults.DEFAULT_COLOR_SCHEME);
    renderer.setPaintScale(paintScale);

    // Add to panel.
    XYPlot responsePlot = new XYPlot(categoryData, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart(responsePlot);
    chart.removeLegend();
    return chart;
}

From source file:Interfaz.adminZone.java

private void graficar() {
    ChartPanel panel;/*from   w w w.  j a va2 s .co m*/
    JFreeChart chart = null;
    int validar = 1;
    XYSplineRenderer renderer = new XYSplineRenderer();
    XYSeriesCollection dataset = new XYSeriesCollection();

    ValueAxis x = new NumberAxis();
    ValueAxis y = new NumberAxis();

    XYSeries serie = new XYSeries("Ventas");

    XYPlot plot;

    lineas.removeAll();

    try {
        for (int fila = 0; fila < this.modeloVentasMes.getRowCount(); fila++) {
            serie.add(Float.parseFloat(String.valueOf(this.modeloVentasMes.getValueAt(fila, 0))),
                    Float.parseFloat(String.valueOf(modeloVentasMes.getValueAt(fila, 1))));

        }
    } catch (Exception es) {
        validar = 0;
    }
    if (validar == 1) {
        dataset.addSeries(serie);

        x.setLabel("Mes");
        y.setLabel("Ventas");
        plot = new XYPlot(dataset, x, y, renderer);
        chart = new JFreeChart(plot);
        chart.setTitle("Cambio en las Ventas 2016");
    }
    panel = new ChartPanel(chart);
    panel.setBounds(5, 10, 229, 219);

    lineas.add(panel);
    lineas.repaint();

}

From source file:org.geoserver.monitor.web.ActivityChartBasePanel.java

JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins 
    timeAxis.setUpperMargin(0.02);/*  ww w .  j  ava2 s  .  com*/
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default

    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(renderer);

    JFreeChart chart = new JFreeChart(plot);

    //TextTitle t = new TextTitle(title);
    //t.setTextAlignment(HorizontalAlignment.LEFT);

    //chart.setTitle(t);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);
    chart.clearSubtitles();

    return chart;
}

From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java

/**
 * Creates new form Chromatogram2DViewerPanel
 *//*w  ww .j  a v  a  2 s . c  o  m*/
public Chromatogram2DViewerPanel(InstanceContent topComponentInstanceContent, Lookup tcLookup,
        ADataset2D<IChromatogram2D, IScan2D> ds, PaintScale ps) {
    initComponents();
    this.content = topComponentInstanceContent;
    this.lookup = tcLookup;
    chart = new JFreeChart(new XYPlot());
    chartPanel = new ContextAwareChartPanel(chart, true, true, true, true, true);
    Cursor crosshairCursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
    chartPanel.setCursor(crosshairCursor);
    //        chart.addProgressListener(cdxpanel);
    chartPanel.setInitialDelay(100);
    chartPanel.setDismissDelay(30000);
    chartPanel.setReshowDelay(0);
    chartPanel.setFocusable(true);
    jPanel2.add(chartPanel, BorderLayout.CENTER);
    content.add(chartPanel);
    addKeyListener(this);
    setPaintScale(ps);
}

From source file:telas.TelaGrafico.java

public void criaGrafico(ArrayList<Processo> listapronto) {
    JFreeChart chart = null;//www  .  j a v  a  2  s .c  o m

    XYSplineRenderer renderer = new XYSplineRenderer();
    XYSeriesCollection dataset = new XYSeriesCollection();

    ValueAxis x = new NumberAxis();
    ValueAxis y = new NumberAxis();

    XYSeries serie = new XYSeries("Processos");

    XYPlot plot;

    for (int fila = 0; fila < listapronto.size(); fila++) {

        serie.add(listapronto.get(fila).getTsurto(), listapronto.get(fila).getTespera());
    }
    dataset.addSeries(serie);
    x.setLabel("Processos");
    y.setLabel("Tempo de espera");
    plot = new XYPlot(dataset, x, y, renderer);

    chart = new JFreeChart(plot);
    chart.setTitle("Processos");

    ChartPanel myChartPanel = new ChartPanel(chart, true);
    myChartPanel.setSize(jPanel1.getWidth(), jPanel1.getHeight());
    myChartPanel.setVisible(true);
    jPanel1.removeAll();
    jPanel1.add(myChartPanel);
    jPanel1.revalidate();
    jPanel1.repaint();
}

From source file:com.bdb.weather.display.RainPlot.java

private void createChartElements() {
    String unitString = Depth.getDefaultUnit().toString();
    rateDomain = String.format(RAIN_RATE_DOMAIN_PREFIX, unitString);
    rainPlot = new XYPlot();
    rainPlot.setRangeAxis(RainRangeAxis.create());
    rainRatePlot = new XYPlot();
    rainRatePlot.setRangeAxis(RainRangeAxis.create());

    plot = new CombinedDomainXYPlot();
    plot.setDomainAxis(new DateAxis("Time"));

    plot.add(rainRatePlot);//  w w w . ja v a2  s.com
    plot.add(rainPlot);

    chart = new JFreeChart(plot);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    chartViewer = new ChartViewer(chart);
    chartViewer.setMaxHeight(10000);
    chartViewer.setMaxWidth(10000);
    chartViewer.setMinHeight(200);
    chartViewer.setMinWidth(400);

    rainDataset = new TimeSeriesCollection();
    rainSeries = new TimeSeries(RAIN_DOMAIN);
    rainDataset.addSeries(rainSeries);
    rainPlot.setDataset(rainDataset);

    rainRateDataset = new TimeSeriesCollection();
    rainRateSeries = new TimeSeries(rateDomain);
    rainRateDataset.addSeries(rainRateSeries);
    rainRatePlot.setDataset(rainRateDataset);

    XYToolTipGenerator ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            DateFormat.getTimeInstance(), Depth.getDefaultFormatter());

    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setBasePaint(Color.BLUE);
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setBaseToolTipGenerator(ttg);
    plot.setRenderer(renderer);

    XYItemRenderer rateRenderer = new XYLineAndShapeRenderer(true, false);
    rateRenderer.setBasePaint(Color.RED);
    rateRenderer.setSeriesPaint(0, Color.RED);
    rateRenderer.setBaseToolTipGenerator(ttg);
    rainRatePlot.setRenderer(rateRenderer);
}

From source file:org.fhaes.jsea.JSEABarChart.java

/**
 * Creates a demo chart.//from  w  ww .j a v a  2s .com
 * 
 * @return A chart.
 */
@SuppressWarnings("deprecation")
public static JFreeChart createChart(String title, double[] meanByWindow, int lengthOfWindow,
        int yearsPriorOfEvent, int yearsAfterEvent, double[][] leftEndPointSim, double[][] rightEndPointSim,
        String outputFilePrefix, int alphaLevel, int segmentIndex) {

    JSEABarChart.meanByWindow = meanByWindow;
    JSEABarChart.lengthOfWindow = lengthOfWindow;
    JSEABarChart.yearsPriorOfEvent = yearsPriorOfEvent;
    JSEABarChart.leftEndPointSim = leftEndPointSim;
    JSEABarChart.rightEndPointSim = rightEndPointSim;
    JSEABarChart.alphaLevel = alphaLevel;

    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(0, createDataset());
    plot.setOrientation(PlotOrientation.VERTICAL);

    CustomBarRenderer renderer = new CustomBarRenderer(createPaint(lengthOfWindow, Color.gray));
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);
    renderer.setOutlinePaint(Color.yellow);
    renderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setRenderer(0, renderer);
    Color allcolors[] = { Color.red, Color.green, Color.blue };

    System.out.println("here is the alphlevel " + alphaLevel);
    // for (int k = 0; k <= 5; k++) {
    // if (k <= 2) {
    // / plot.setDataset(k + 1, createEndDataset(k, true));
    // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k], k));
    // } else {
    // plot.setDataset(k + 1, createEndDataset(k - 3, false));
    // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k - 3], k - 3));
    // }
    // }
    // for (int k = 0; k <1; k++) {
    // if (k <= 2) {
    plot.setDataset(1, createEndDataset(alphaLevel, true));
    plot.setRenderer(1, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel));
    // } else {
    plot.setDataset(4, createEndDataset(alphaLevel, false));
    plot.setRenderer(4, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel));
    // }
    // }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainAxis(new CategoryAxis("LAG"));

    plot.addRangeMarker(new ValueMarker(0));

    plot.setRangeAxis(new NumberAxis(outputFilePrefix));
    plot.setRangeGridlinesVisible(true);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(title);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

public void createEmptyChart() {
    setChart(new JFreeChart(new XYPlot()));
}

From source file:DashboardInterface.TensionSpeedDial.java

public TensionSpeedDial(JPanel parentIn) {
    super(new BorderLayout());
    parent = parentIn;/*from w ww.  j a v  a 2 s .c  o m*/
    dataset1 = new DefaultValueDataset(0D);
    dataset2 = new DefaultValueDataset(0D);
    pipe = MessagePipeline.getInstance();
    pipe.attach(this);
    DialPlot dialplot = new DialPlot();
    dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
    dialplot.setDataset(0, dataset1);
    dialplot.setDataset(1, dataset2);
    setBackground(Color.WHITE);
    StandardDialFrame standarddialframe = new StandardDialFrame();
    standarddialframe.setBackgroundPaint(Color.lightGray);
    standarddialframe.setForegroundPaint(Color.darkGray);

    dialplot.setDialFrame(standarddialframe);

    DialBackground dialbackground = new DialBackground(Color.LIGHT_GRAY);

    dialbackground.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialplot.setBackground(dialbackground);

    DialTextAnnotation dialtextannotation = new DialTextAnnotation("Tension (lbf)");
    dialtextannotation.setFont(new Font("Dialog", 1, 12));
    dialtextannotation.setPaint(Color.RED);
    dialtextannotation.setRadius(0.47999999999999996D);
    dialplot.addLayer(dialtextannotation);

    DialTextAnnotation dialtextannotation2 = new DialTextAnnotation("Speed (kts)");
    dialtextannotation2.setFont(new Font("Dialog", 1, 12));
    dialtextannotation2.setPaint(Color.BLUE);
    dialtextannotation2.setRadius(0.78999999999999996D);
    dialplot.addLayer(dialtextannotation2);

    /*DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
    dialvalueindicator.setFont(new Font("Dialog", 0, 10));
    dialvalueindicator.setOutlinePaint(Color.BLACK);
    dialvalueindicator.setRadius(0.84999999999999998D);
    dialvalueindicator.setAngle(-90D);
    dialplot.addLayer(dialvalueindicator);
            
    DialValueIndicator dialvalueindicator1 = new DialValueIndicator(1);
    dialvalueindicator1.setFont(new Font("Dialog", 0, 10));
    dialvalueindicator1.setOutlinePaint(Color.BLACK);
    dialvalueindicator1.setRadius(0.60999999999999998D);
    dialvalueindicator1.setAngle(-90D);
    dialplot.addLayer(dialvalueindicator1);*/

    StandardDialScale standarddialscale = new StandardDialScale(0D, 90D, -120D, -300D, 10D, 4);
    standarddialscale.setTickRadius(0.88D);
    standarddialscale.setTickLabelOffset(0.14999999999999999D);
    standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
    standarddialscale.setTickLabelPaint(Color.BLUE);
    standarddialscale.setMajorTickPaint(Color.BLUE);
    standarddialscale.setMinorTickPaint(Color.BLUE);
    dialplot.addScale(0, standarddialscale);

    StandardDialScale standarddialscale1 = new StandardDialScale(0.0D, 2500D, -120D, -300D, 500D, 4);
    standarddialscale1.setTickRadius(0.5D);
    standarddialscale1.setTickLabelOffset(0.14999999999999999D);
    standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
    standarddialscale1.setTickLabelPaint(Color.RED);
    standarddialscale1.setMajorTickPaint(Color.RED);
    standarddialscale1.setMinorTickPaint(Color.RED);
    dialplot.addScale(1, standarddialscale1);

    dialplot.mapDatasetToScale(1, 1);

    org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(
            0);
    pointer.setFillPaint(Color.BLUE);
    dialplot.addPointer(pointer);

    org.jfree.chart.plot.dial.DialPointer.Pointer pin = new org.jfree.chart.plot.dial.DialPointer.Pointer(1);
    pin.setRadius(0.55000000000000004D);
    pin.setFillPaint(Color.RED);
    dialplot.addPointer(pin);

    DialCap dialcap = new DialCap();
    dialcap.setRadius(0.10000000000000001D);
    dialplot.setCap(dialcap);

    Dimension size = parent.getBounds().getSize();
    int width = parent.getWidth();
    int height = parent.getHeight();

    width = 200;

    JFreeChart jfreechart = new JFreeChart(dialplot);
    jfreechart.setBackgroundPaint(Color.WHITE);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(width, width));

    add(chartpanel);
}

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java

private static JFreeChart createChart() {

    ///*from w w  w  . j  a  v a2  s .co m*/
    DefaultCategoryDataset Pactual = jFreeChartDataSets.get(CoreConfiguration.PACTUAL_LABEL);
    DefaultCategoryDataset Ppredicted = jFreeChartDataSets.get(CoreConfiguration.PPREDICTED_LABEL);

    StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator();

    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    /*renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
    renderer1.setBaseItemLabelsVisible(true);*/
    StackedAreaRenderer renderer2 = new StackedAreaRenderer();

    //plot
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(Ppredicted);
    plot.setRenderer(renderer2);
    plot.setDataset(1, Pactual);
    plot.setRenderer(1, renderer1);
    CategoryAxis axis = new CategoryAxis("Sample");
    axis.setTickLabelsVisible(false);
    axis.setCategoryMargin(0.0);
    plot.setDomainAxis(axis);

    //more rangeAxis
    plot.setRangeAxis(new NumberAxis("Power (Watts)"));
    plot.mapDatasetToRangeAxis(2, 1);
    //
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    //chart
    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(NAME);
    return chart;
}