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:userinterface.CyberSecurity.ChartFactory.java

public static ChartPanel createChart(UserAccount account) {
    Map<String, LoginDetails> loginDetails = account.getLoginDetails();
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();

    Collection<LoginDetails> values = loginDetails.values();

    for (LoginDetails details : values) {
        dataset1.addValue(TimeUnit.MILLISECONDS.toHours(details.getLogoutTime() - details.getLoginTime()),
                HOURS_WORKED_BY_USER, details.getLoginDate());
        dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, details.getLoginDate());
    }/*from   www.j  av  a2s . co  m*/

    dataset1.addValue(2, HOURS_WORKED_BY_USER, "4-19-2016");
    dataset1.addValue(3, HOURS_WORKED_BY_USER, "4-20-2016");
    dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-19-2016");
    dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-20-2016");

    final CategoryItemRenderer renderer = new BarRenderer();

    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset1);
    plot.setRenderer(renderer);

    plot.setDomainAxis(new CategoryAxis("Date"));
    plot.setRangeAxis(new NumberAxis("Hours"));

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // now create the second dataset and renderer...
    final CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    final JFreeChart chart = new JFreeChart(plot);
    chart.setTitle("Employee work hours");

    chart.setBackgroundPaint(Color.WHITE);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    return chartPanel;
}

From source file:AsymptoticFreedom.GraphViewPanel.java

public JFreeChart getResultChart() {
    // XY ?//  w  w w.  j a va2s .c  o m
    int quark_size = ViewPanel.quark_list.size();
    if (quark_size < 2)
        return new JFreeChart(new XYPlot());

    // XY Dataset  
    XYSeriesCollection data = new XYSeriesCollection();
    //System.out.println(series.get(0).getY(30));
    for (XYSeries s : series) {
        data.addSeries(s);
    }

    final JFreeChart chart = ChartFactory.createXYLineChart("Potential", "Distance", "Potential", data,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setTitle("Potential of quarks"); //  ?
    XYPlot plot = (XYPlot) chart.getPlot();
    //plot.addRangeMarker(new ValueMarker(15,Color.RED,new BasicStroke(2.0f)));
    for (int i = 0; i < quark_size; i++) {
        for (int j = i + 1; j < quark_size; j++) {
            Quark quark1 = ViewPanel.quark_list.get(i);
            Quark quark2 = ViewPanel.quark_list.get(j);
            double distance = quark1.pos.distance(quark2.pos);
            double value = quark1.calculatePotential(quark2);
            String anno_title = String.format("V_ %c-%c", quark1.color.charAt(0), quark2.color.charAt(0));
            //System.out.println(anno_title);
            XYPointerAnnotation pointer = new XYPointerAnnotation(anno_title, distance, value,
                    3.0 * Math.PI / 4.0);
            plot.addAnnotation(pointer);
        }
    }
    plot.getRangeAxis().setRange(-500, 4000);
    return chart;
}

From source file:de.cebitec.readXplorer.plotting.CreatePlots.java

public synchronized static ChartPanel createPlot(Map<PersistentFeature, Pair<Double, Double>> data,
        String xName, String yName, XYToolTipGenerator toolTip) {
    XYSeriesCollection normal = new XYSeriesCollection();
    XYSeries nor = new XYSeries("Normal");
    for (Iterator<PersistentFeature> it = data.keySet().iterator(); it.hasNext();) {
        PersistentFeature key = it.next();
        Pair<Double, Double> pair = data.get(key);
        Double X = pair.getFirst();
        Double Y = pair.getSecond();
        nor.add(new PlotDataItem(key, X, Y));
    }/*from   w ww.  j  av  a  2  s  .  c  om*/
    normal.addSeries(nor);
    // create subplot 1...
    final XYItemRenderer renderer1 = new XYShapeRenderer();
    renderer1.setBaseToolTipGenerator(toolTip);
    final NumberAxis domainAxis1 = new NumberAxis(xName);
    final NumberAxis rangeAxis1 = new NumberAxis(yName);
    final XYPlot subplot1 = new XYPlot(normal, domainAxis1, rangeAxis1, renderer1);
    JFreeChart chart = new JFreeChart(subplot1);
    chart.removeLegend();
    ChartPanel panel = new ChartPanel(chart, true, false, true, true, true);
    panel.setInitialDelay(0);
    panel.setMaximumDrawHeight(1080);
    panel.setMaximumDrawWidth(1920);
    panel.setMouseWheelEnabled(true);
    panel.setMouseZoomable(true);
    MouseActions mouseAction = new MouseActions();
    panel.addChartMouseListener(mouseAction);
    ChartPanelOverlay overlay = new ChartPanelOverlay(mouseAction);
    panel.addOverlay(overlay);
    return panel;
}

From source file:Panels.FinanzPanel.java

public FinanzPanel(DetailContainer dc) {
    this.dc = dc;
    initComponents();//from   ww  w  .java2  s.  com
    dataset = new DefaultPieDataset();
    ;
    //        //dataset.addSeries("xy", A);
    //        dataset.setValue("One", new Double(43.2));
    //        dataset.setValue("Two", new Double(10.0));
    renderer = new XYSplineRenderer();
    ////        xax = new NumberAxis("x");
    ////        yax = new NumberAxis("y");
    plot = new PiePlot(dataset);
    //        //plot = new XYPlot(dataset,xax,yax, renderer);
    chart1 = new JFreeChart(plot);
    chartPanel1 = new ChartPanel(chart1);
    chartPanel1.setMouseWheelEnabled(true);
    //        this.jPanel1.setLayout(new java.awt.BorderLayout());
    this.jPanel1.add(chartPanel1);
    this.jButton1.setModel(new DefaultButtonModel());
    //        this.add(new JButton("back"), BorderLayout.SOUTH );
    this.validate();
}

From source file:com.bdb.weather.display.summary.TemperatureBinSummaryPlot.java

public TemperatureBinSummaryPlot() {
    plot = new CombinedDomainCategoryPlot();
    JFreeChart chart = new JFreeChart(plot);
    setMaxHeight(10000);//from   www .j  a v a  2s  .c o  m
    setMaxWidth(10000);

    NumberAxis countAxis = new NumberAxis("Day Count");
    countAxis.setUpperMargin(.2);
    countPlot.setRangeAxis(countAxis);
    countPlot.setDataset(countDataset);

    BarRenderer r = new BarRenderer();
    r.setBaseItemLabelsVisible(true);
    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    r.setSeriesPaint(0, Color.BLUE);
    r.setBasePaint(Color.BLUE);
    countPlot.setRenderer(r);

    NumberAxis durationAxis = new NumberAxis("Duration (Hours)");
    durationAxis.setUpperMargin(.2);
    durationPlot.setRangeAxis(durationAxis);
    durationPlot.setDataset(durationDataset);
    r = new BarRenderer();
    r.setBaseItemLabelsVisible(true);
    NumberFormat format = DecimalFormat.getNumberInstance();
    format.setMaximumFractionDigits(1);
    format.setMinimumFractionDigits(1);
    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, format));
    r.setSeriesPaint(0, Color.RED);
    r.setBasePaint(Color.RED);
    durationPlot.setRenderer(r);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    plot.add(countPlot);
    plot.add(durationPlot);

    chartViewer = new ChartViewer(chart);
    this.setCenter(chartViewer);
}

From source file:electroStaticUI.DrawElectricFieldLines.java

public DrawElectricFieldLines(CustomMapper cMapper) {
    mapper = cMapper;//  w  w w. j  a v a2s .  c o  m
    sumTotalVector();
    createDataset();
    renderer = new VectorRenderer();
    graph = new XYPlot(dataSet, new NumberAxis("Axis X"), new NumberAxis("Axis Y"), renderer);
    eFieldChart = new JFreeChart(graph);
    eFieldChart.setTitle("Electric Field Vectors");
    graphChart = new ChartPanel(eFieldChart);
    graphChart.setVisible(true);
}

From source file:org.jls.toolbox.math.chart.Thermometer.java

/**
 * Permet de crer et de paramtrer le thermomtre.
 *//*ww  w  .ja  v  a  2s  . com*/
private void createChart() {
    this.plot = new ThermometerPlot(this.dataset);
    this.chart = new JFreeChart(this.plot);

    this.plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    this.plot.setPadding(new RectangleInsets(0, 0, 0, 0));
    this.plot.setThermometerStroke(new BasicStroke(1.0f));
    this.plot.setThermometerPaint(Color.black);
    this.plot.setFollowDataInSubranges(true);
    this.plot.setRange(0, 100);
    this.plot.setForegroundAlpha(100);

    // this.chart.setBackgroundPaint(new JPanel().getBackground());
    this.chart.setAntiAlias(true);
    this.chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    this.chart.setTitle(this.title);

    this.panel = new ChartPanel(this.chart);
    double coeff = 0.3;
    int width = (int) (this.panel.getPreferredSize().getWidth() * coeff);
    int height = (int) (this.panel.getPreferredSize().getHeight() * coeff);
    this.panel.setPreferredSize(new Dimension(width, height));
}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java

public static ChartPanel CreateChartPanel(java.util.List datasets, Color[] colors) {
    if (datasets.size() == 1)
        return CreateChartPanel((XYSeriesCollection) datasets.get(0), colors);

    CombinedDomainXYPlot combined = new CombinedDomainXYPlot();
    for (Iterator it = datasets.iterator(); it.hasNext();) {
        XYSeriesCollection series = (XYSeriesCollection) it.next();
        XYPlot xy = createXYPlot(series, colors);
        combined.add(xy);// ww w.j a  va  2s.co  m
    }
    NumberAxis axisDomain = new NumberAxis();
    axisDomain.setAutoRangeIncludesZero(false);
    //      axisDomain.setRange(400.0, 1600.0);
    combined.setDomainAxis(axisDomain);

    JFreeChart chart = new JFreeChart(combined);
    ChartPanel chartPanel = new SpectrumChartPanel(chart);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setMouseZoomable(true);
    // Remove the autogenerated subtitle
    if (chart.getSubtitleCount() == 1)
        chart.removeSubtitle(chart.getSubtitle(chart.getSubtitleCount() - 1));
    return chartPanel;
}

From source file:maltcms.ui.fileHandles.serialized.JFCPanel.java

/**
 *
 *//*  w  w  w . j ava 2 s .c  om*/
public JFCPanel() {
    this.chartPanel = new ChartPanel(new JFreeChart(new XYPlot()));

    initComponents();
    jToggleButton1ActionPerformed(new ActionEvent(this, 0, ""));
    toggleYAxisFix = new JToggleButton(new AbstractAction("Fix y") {

        @Override
        public void actionPerformed(ActionEvent ae) {
            chartPanel.getChart().getXYPlot().getRangeAxis()
                    .setAutoRange(!chartPanel.getChart().getXYPlot().getRangeAxis().isAutoRange());
        }
    });
    this.jToolBar2.add(toggleYAxisFix);

    toggleXAxisFix = new JToggleButton(new AbstractAction("Fix x") {

        @Override
        public void actionPerformed(ActionEvent ae) {
            chartPanel.getChart().getXYPlot().getDomainAxis()
                    .setAutoRange(!chartPanel.getChart().getXYPlot().getDomainAxis().isAutoRange());
        }
    });
    this.jToolBar2.add(toggleXAxisFix);

    toggleAnnotations = new JToggleButton(new AbstractAction("Annotations") {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (chartPanel.getChart().getXYPlot().getAnnotations().isEmpty()) {
                Logger.getLogger(getClass().getName()).info("Adding annotations");
                for (XYAnnotation xya : annotations) {
                    chartPanel.getChart().getXYPlot().addAnnotation(xya);
                }
                chartPanel.getChart().fireChartChanged();
                toggleAnnotations.setSelected(true);
            } else {
                Logger.getLogger(getClass().getName()).info("Removing annotations");
                List<?> l = chartPanel.getChart().getXYPlot().getAnnotations();
                if (!l.isEmpty()) {
                    annotations.clear();
                    for (Object o : l) {
                        annotations.add((XYAnnotation) o);
                    }
                }
                chartPanel.getChart().getXYPlot().clearAnnotations();
            }
        }
    });
    this.jToolBar2.add(toggleAnnotations);
    toggleAnnotations.setSelected(true);
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.BaseChartBuilderTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    Plot plot = new CategoryPlot();
    _jFreeChart = new JFreeChart(plot);

    when(_chartingDefinition.getChartTitle()).thenReturn(CHART_TITLE);
    when(_chartingDefinition.getChartSubtitle()).thenReturn(CHART_SUB_TITLE);
    when(_chartingDefinition.getXAxisTitle()).thenReturn(X_TITLE);
    when(_chartingDefinition.getYAxisTitle()).thenReturn(Y_TITLE);
    when(_chartingDefinition.getSeriesDefinitions()).thenReturn(_seriesDefinitions);
}