Example usage for org.jfree.chart JFreeChart setBorderVisible

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

Introduction

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

Prototype

public void setBorderVisible(boolean visible) 

Source Link

Document

Sets a flag that controls whether or not a border is drawn around the outside of the chart.

Usage

From source file:ch.epfl.leb.sass.ijplugin.SimulatorStatusFrame.java

/** 
 * Creates a new status frame./*  w ww  . ja va 2s.  c  o m*/
 * 
 * @param groundTruthYLabel The y-axis label for the ground truth signal.
 * @param analyzerYLabel The units output by the analyzer.
 * @param setpointYLabel The units of the controller setpoint.
 * @param outputYLabel The units output by the controller.
 */
public SimulatorStatusFrame(String groundTruthYLabel, String analyzerYLabel, String setpointYLabel,
        String outputYLabel) {
    String seriesLabel = "";
    String yLabel = "";
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new NumberAxis("Simulation Outputs"));
    Font yLabelFont = new Font("Dialog", Font.PLAIN, 10);
    datasets = new XYSeriesCollection[4];
    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        switch (i) {
        case 0:
            seriesLabel = "True density";
            yLabel = groundTruthYLabel;
            break;
        case 1:
            seriesLabel = "Analyzer output";
            yLabel = analyzerYLabel;
            break;
        case 2:
            seriesLabel = "Setpoint";
            yLabel = setpointYLabel;
            break;
        case 3:
            seriesLabel = "Controller output";
            yLabel = outputYLabel;
            break;
        }

        XYSeries timeseries = new XYSeries(seriesLabel);
        datasets[i] = new XYSeriesCollection(timeseries);

        NumberAxis numberaxis = new NumberAxis(yLabel);
        numberaxis.setAutoRangeIncludesZero(false);
        numberaxis.setNumberFormatOverride(new DecimalFormat("###0.00"));
        XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer());
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        xyplot.getRangeAxis().setLabelFont(yLabelFont);
        combineddomainxyplot.add(xyplot);
    }

    JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, true);
    jfreechart.setBorderPaint(Color.black);
    jfreechart.setBorderVisible(true);
    jfreechart.setBackgroundPaint(Color.white);
    combineddomainxyplot.setBackgroundPaint(Color.lightGray);
    combineddomainxyplot.setDomainGridlinePaint(Color.white);
    combineddomainxyplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    // Number of frames to display
    valueaxis.setFixedAutoRange(2000D);

    ChartPanel chartpanel = new ChartPanel(jfreechart);

    chartpanel.setPreferredSize(new Dimension(800, 500));
    chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    chartpanel.setVisible(true);

    JPanel jPanel = new JPanel();
    jPanel.setLayout(new BorderLayout());
    jPanel.add(chartpanel, BorderLayout.NORTH);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    add(jPanel);
    pack();
    setVisible(true);

}

From source file:org.ietr.preesm.mapper.ui.stats.PerformancePlotter.java

/**
 * Creates a chart in order to plot the speed-ups.
 * //from   w  ww.  j  ava  2 s .c o m
 * @return A chart.
 */
private JFreeChart createChart(String title) {

    // Creating display domain
    NumberAxis horizontalAxis = new NumberAxis("Number of operators");
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(horizontalAxis);

    // Creating the best speedups subplot
    this.speedups = new DefaultXYDataset();

    final NumberAxis xAxis = new NumberAxis("speedups");

    xAxis.setAutoRangeIncludesZero(false);

    XYSplineRenderer renderer = new XYSplineRenderer();
    final XYPlot subplot = new XYPlot(this.speedups, null, xAxis, renderer);

    subplot.setBackgroundPaint(Color.white);
    subplot.setDomainGridlinePaint(Color.lightGray);
    subplot.setRangeGridlinePaint(Color.lightGray);
    plot.add(subplot);

    plot.setForegroundAlpha(0.5f);

    final JFreeChart chart = new JFreeChart(title, plot);

    chart.setBorderPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);

    return chart;

}

From source file:org.jfree.chart.demo.DynamicDataDemo3.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*from   w  w w.  ja va  2  s . c  om*/
 */
public DynamicDataDemo3(final String title) {

    super(title);

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        this.lastValue[i] = 100.0;
        final TimeSeries series = new TimeSeries("Random " + i, Millisecond.class);
        this.datasets[i] = new TimeSeriesCollection(series);
        final NumberAxis rangeAxis = new NumberAxis("Y" + i);
        rangeAxis.setAutoRangeIncludesZero(false);
        final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    final JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);
    //        chart.getLegend().setAnchor(Legend.EAST);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        final JButton button = new JButton("Series " + i);
        button.setActionCommand("ADD_DATA_" + i);
        button.addActionListener(this);
        buttonPanel.add(button);
    }
    final JButton buttonAll = new JButton("ALL");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

}

From source file:id.aas.apps.mvc.view.chartFrame.java

void pie() {
    try {//from  w  w w . j a  va 2s  . co  m
        int nilaiKiloan = 0;
        int nilaiSatuan = 0;
        //create pie chart
        String queryKiloan = "SELECT COUNT(*) FROM laundry WHERE jenis_layanan='Laundry Kiloan'";
        String querySatuan = "SELECT COUNT(*) FROM laundry WHERE jenis_layanan='Laundry Satuan'";
        ConnectionDB.InstanceDB.openConnection();
        ResultSet rs = ConnectionDB.InstanceDB.RunSelectQuery(queryKiloan);
        while (rs.next()) {
            nilaiKiloan = rs.getInt(1);
        }
        System.out.println(nilaiKiloan);

        ResultSet rs1 = ConnectionDB.InstanceDB.RunSelectQuery(querySatuan);
        while (rs1.next()) {
            nilaiSatuan = rs1.getInt(1);
        }
        System.out.println(nilaiSatuan);
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("Laundry Kiloan", nilaiKiloan);
        pieDataset.setValue("Laundry Satuan", nilaiSatuan);

        JFreeChart chart = ChartFactory.createPieChart3D("Perbandingan Pengguna Layanan Laundry", pieDataset,
                true, true, false);

        chart.setBorderVisible(false);
        chart.setBackgroundPaint(null);

        ChartPanel cPanel = new ChartPanel(chart);
        setBounds(100, 100, 685, 429);
        jPanel1 = new JPanel();
        jPanel1.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(jPanel1);
        jPanel1.setLayout(null);
        jPanel1.add(cPanel);
        jTabbedPane1.add(jPanel1);
        setVisible(true);

        //            BufferedImage image3 = chart.createBufferedImage(500, 300);
        //            jLabel2.setIcon(new ImageIcon(image3));
        //            jLabel2.setLocation(20, 20);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}

From source file:org.loklak.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = (String) iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }/*from w  w w  .ja  va2 s .co m*/

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:ai.susi.server.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator<String> iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }/*from  w w  w.j  a  v  a 2  s.  co  m*/

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:id.aas.apps.mvc.view.chartFrame.java

void bar() {
    try {//w w  w  .j  av  a 2  s.c  o m
        double Lunas = 0;
        double Casbon = 0;

        String queryLunas = "SELECT SUM(total_tagihan) from transaksi where keterangan='Lunas'";
        String queryCasbon = "SELECT SUM(total_tagihan) from transaksi where keterangan='Cash Bon'";
        ConnectionDB.InstanceDB.openConnection();
        ResultSet rs = ConnectionDB.InstanceDB.RunSelectQuery(queryLunas);
        while (rs.next()) {
            Lunas = rs.getDouble(1);
        }
        System.out.println(Lunas);

        ResultSet rs1 = ConnectionDB.InstanceDB.RunSelectQuery(queryCasbon);
        while (rs1.next()) {
            Casbon = rs1.getDouble(1);
        }
        System.out.println(Casbon);
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(Lunas, "Lunas", "Catatan Uang Pendapatan");
        dataset.setValue(Casbon, "Cash Bon", "Catatan Uang Pendapatan");

        JFreeChart chart = ChartFactory.createBarChart3D("Catatan Uang Pendapatan dan Piutang Laundry",
                "Keterangan Pembayaran", "Jumlah Uang", dataset);
        chart.setBorderVisible(false);
        chart.setBackgroundPaint(null);

        //            BufferedImage image = chart.createBufferedImage(500, 300);
        //            jLabel1.setIcon(new ImageIcon(image));
        ChartPanel cPanel = new ChartPanel(chart);
        setBounds(100, 100, 685, 429);
        jPanel2 = new JPanel();
        jPanel2.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(jPanel2);
        jPanel2.setLayout(null);
        jPanel2.add(cPanel);
        jTabbedPane1.add(jPanel2);
        setVisible(true);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:com.marvelution.jira.plugins.hudson.charts.BuildResultsRatioChartGenerator.java

/**
 * {@inheritDoc}//from  w w  w  .j a  v  a  2 s  .  c  om
 */
@Override
public ChartHelper generateChart() {
    final Map<Integer, Build> buildMap = new HashMap<Integer, Build>();
    final CategoryTableXYDataset dataSet = new CategoryTableXYDataset();
    for (Build build : builds) {
        buildMap.put(Integer.valueOf(build.getBuildNumber()), build);
        dataSet.add(Double.valueOf(build.getBuildNumber()), Double.valueOf(build.getDuration()),
                getI18n().getText("hudson.charts.duration"));
    }
    final JFreeChart chart = ChartFactory.createXYBarChart("", "", false,
            getI18n().getText("hudson.charts.duration"), dataSet, PlotOrientation.VERTICAL, false, false,
            false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);
    final BuildResultRenderer renderer = new BuildResultRenderer(server, buildMap);
    renderer.setBaseItemLabelFont(ChartDefaults.defaultFont);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setMargin(0.0D);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseToolTipGenerator(renderer);
    renderer.setURLGenerator(renderer);
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setAxisOffset(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    xyPlot.setRenderer(renderer);
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setLowerBound(Collections.min(buildMap.keySet()));
    domainAxis.setUpperBound(Collections.max(buildMap.keySet()));
    final TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    domainAxis.setStandardTickUnits(ticks);
    xyPlot.setDomainAxis(domainAxis);
    final DateAxis rangeAxis = new DateAxis();
    final DurationFormat durationFormat = new DurationFormat();
    rangeAxis.setDateFormatOverride(durationFormat);
    rangeAxis.setLabel(getI18n().getText("hudson.charts.duration"));
    xyPlot.setRangeAxis(rangeAxis);
    ChartUtil.setupPlot(xyPlot);
    return new ChartHelper(chart);
}

From source file:com.algodefu.yeti.data.Pass.java

private void calculateEquityChartImg() throws IOException {
    int i = 0;//from w  w w . j a  v a  2 s  .co  m
    double sum = 0;
    TimeSeries equity = new TimeSeries("Equity");

    // save values in temp array first, then use System.arraycopy to copy non empty values to this.equityArray
    double[][] tempEquityArr = new double[this.getTrades().length][4];

    for (Trade trade : this.getTrades()) {
        if (trade.getCloseDateTime() != null) {
            sum += trade.getProfit();
            equity.add(new Millisecond(Date.from(trade.getCloseDateTime().toInstant(ZoneOffset.UTC))), sum);
            tempEquityArr[i][0] = (double) trade.getCloseDateTime().toInstant(ZoneOffset.UTC).toEpochMilli();
            tempEquityArr[i][1] = sum;
            tempEquityArr[i][2] = trade.getTradeID();
            tempEquityArr[i][3] = trade.getProfit();
            i++;
        }
    }
    this.equityArray = new double[i][4];
    System.arraycopy(tempEquityArr, 0, this.equityArray, 0, i);

    TimeSeriesCollection dataset = new TimeSeriesCollection(equity);
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false);
    chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false);
    chart.setBorderVisible(true);
    chart.getXYPlot().setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.blue);
    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setRangeGridlinePaint(Color.gray);
    chart.getXYPlot().setDomainGridlinePaint(Color.gray);
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        ChartUtilities.writeChartAsPNG(baos, chart, 320, 180);
        baos.flush();
        this.equityChartByteArray = baos.toByteArray();
    } catch (IOException e) {
        throw e;
    }

}

From source file:dinamica.SyncChartOutput.java

public void print(GenericTransaction t) throws Throwable {

    //get chart parameters
    Recordset chartinfo = t.getRecordset("chartinfo");

    //get chart data
    String id = chartinfo.getString("data");
    Recordset data = (Recordset) getSession().getAttribute(id);
    if (data == null)
        throw new Throwable(
                "Invalid Recordset ID:" + id + " - The session does not contain an attribute with this ID.");

    //general chart params
    Integer width = (Integer) chartinfo.getValue("width");
    Integer height = (Integer) chartinfo.getValue("height");

    //load chart plugin
    String plugin = (String) chartinfo.getValue("chart-plugin");
    AbstractChartPlugin obj = (AbstractChartPlugin) Thread.currentThread().getContextClassLoader()
            .loadClass(plugin).newInstance();

    JFreeChart chart = null;
    synchronized (data) {
        chart = obj.getChart(chartinfo, data);
    }/*  www  .j a  v a 2  s  . com*/

    //set gradient
    chart.setBackgroundPaint(getGradient());

    //set border and legend params
    chart.setBorderPaint(Color.LIGHT_GRAY);
    chart.setBorderVisible(true);
    if (chart.getLegend() != null) {
        chart.getLegend().setBorder(0.2, 0.2, 0.2, 0.2);
        chart.getLegend().setPadding(5, 5, 5, 5);
        chart.getLegend().setMargin(4, 5, 4, 4);
    }

    //render chart in memory
    BufferedImage img = chart.createBufferedImage(width.intValue(), height.intValue());
    ByteArrayOutputStream b = new ByteArrayOutputStream(32768);

    //encode as PNG
    ImageIO.write(img, "png", b);

    //send bitmap via servlet output
    byte image[] = b.toByteArray();
    getResponse().setContentType("image/png");
    getResponse().setContentLength(image.length);
    OutputStream out = getResponse().getOutputStream();
    out.write(image);
    out.close();

    //save image bytes in session attribute if requested
    if (chartinfo.containsField("session")) {
        String session = chartinfo.getString("session");
        if (session != null && session.equals("true"))
            getSession().setAttribute(chartinfo.getString("image-id"), image);
    }

}