Example usage for org.jfree.chart ChartPanel setDomainZoomable

List of usage examples for org.jfree.chart ChartPanel setDomainZoomable

Introduction

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

Prototype

public void setDomainZoomable(boolean flag) 

Source Link

Document

Sets the flag that controls whether or not zooming is enabled for the domain axis.

Usage

From source file:org.jgrasstools.gears.ui.OmsMatrixCharter.java

@Execute
public void chart() throws Exception {
    if (inData == null && inDataXY == null) {
        throw new ModelsIllegalargumentException("At least one of the datasets need to be valid.", this, pm);
    }/*  w w w  . j  a va 2  s .co m*/

    if (doDump) {
        checkNull(inChartPath);
    }

    JFreeChart chart = null;
    if (pType == 0) {
        chart = doLineChart();
    } else {
        chart = doBarChart();
    }
    if (inSubTitle != null) {
        TextTitle subTitle = new TextTitle(inSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.setTextAntiAlias(true);

    if (doDump) {
        File chartFile = new File(inChartPath);
        if (!chartFile.getName().endsWith(".png")) {
            chartFile = FileUtilities.substituteExtention(chartFile, "png");
        }
        BufferedImage bufferedImage = chart.createBufferedImage(pWidth, pHeight);
        ImageIO.write(bufferedImage, "png", chartFile);
    }

    if (doChart) {
        ChartPanel cp = new ChartPanel(chart);
        cp.setDomainZoomable(true);
        cp.setRangeZoomable(true);

        ApplicationFrame af = new ApplicationFrame("");
        af.setContentPane(cp);
        af.setPreferredSize(new Dimension(pWidth, pHeight));
        af.pack();
        af.setVisible(true);
        RefineryUtilities.centerFrameOnScreen(af);
    }
}

From source file:lu.lippmann.cdb.ext.hydviga.data.StationsDataProvider.java

private ChartPanel buildMapPanel(final Instances dataSet, final int xidx, final int yidx,
        final boolean withLegend) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final Map<Integer, java.util.List<Instance>> filteredInstances = new HashMap<Integer, java.util.List<Instance>>();
    final int classIndex = dataSet.classIndex();
    if (classIndex < 0) {
        final XYSeries series = new XYSeries("Serie", false);
        for (int i = 0; i < dataSet.numInstances(); i++) {
            series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
        }/*  ww  w.  ja  va  2  s  .  co  m*/
        data.addSeries(series);
    } else {
        final Set<String> pvs = new TreeSet<String>(
                WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex));
        int p = 0;
        for (final String pv : pvs) {
            final XYSeries series = new XYSeries(pv, false);
            for (int i = 0; i < dataSet.numInstances(); i++) {
                if (dataSet.instance(i).stringValue(classIndex).equals(pv)) {
                    if (!filteredInstances.containsKey(p)) {
                        filteredInstances.put(p, new ArrayList<Instance>());
                    }
                    filteredInstances.get(p).add(dataSet.instance(i));

                    series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
                }
            }
            data.addSeries(series);

            p++;
        }

    }

    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            dataSet.attribute(xidx).name(), // x axis label
            dataSet.attribute(yidx).name(), // y axis label
            data, // data
            PlotOrientation.VERTICAL, withLegend, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setBackgroundImage(shapeImage);

    final XYItemRenderer renderer = xyPlot.getRenderer();
    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            if (classIndex < 0) {
                return InstanceFormatter.htmlFormat(dataSet.instance(item), true);
            } else {
                return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true);
            }
        }
    };

    xyPlot.getRangeAxis().setVisible(false);
    xyPlot.getDomainAxis().setVisible(false);

    xyPlot.getRangeAxis().setLowerBound(60000);
    xyPlot.getRangeAxis().setUpperBound(135000);
    xyPlot.getDomainAxis().setLowerBound(45000);
    xyPlot.getDomainAxis().setUpperBound(110000);

    xyPlot.setDomainGridlinesVisible(false);
    xyPlot.setRangeGridlinesVisible(false);

    xyPlot.setBackgroundPaint(Color.white);

    int nbSeries;
    if (classIndex < 0) {
        nbSeries = 1;
    } else {
        nbSeries = filteredInstances.keySet().size();
    }

    for (int i = 0; i < nbSeries; i++) {
        renderer.setSeriesToolTipGenerator(i, gen);
    }

    final XYItemLabelGenerator lg = new XYItemLabelGenerator() {
        @Override
        public String generateLabel(final XYDataset ds, final int series, final int item) {
            final Instance iii = filteredInstances.get(series).get(item);
            if (iii.stringValue(3).equals(SELECTED_STATUS)) {
                final String label = iii.stringValue(0);
                return label.substring(0, label.length() - 4);
            } else
                return null;
        }
    };
    xyPlot.getRenderer().setBaseItemLabelGenerator(lg);
    xyPlot.getRenderer().setBaseItemLabelsVisible(true);
    xyPlot.getRenderer().setBaseItemLabelFont(new Font("Tahoma", Font.PLAIN, 12));

    xyPlot.getRenderer().setSeriesPaint(1, Color.BLUE);
    xyPlot.getRenderer().setSeriesPaint(0, new Color(210, 210, 210));
    xyPlot.getRenderer().setSeriesPaint(2, Color.DARK_GRAY);

    //System.out.println("shape -> "+xyPlot.getRenderer().getSeriesStroke(0));

    final ChartPanel cp = new ChartPanel(chart);
    cp.setDomainZoomable(false);
    cp.setRangeZoomable(false);

    return cp;
}

From source file:fi.smaa.jsmaa.gui.views.CriterionView.java

private JPanel buildValueFunctionChartPanel(ScaleCriterion criterion) {
    UtilityFunctionDataset dataset = new UtilityFunctionDataset(criterion);

    JFreeChart chart = ChartFactory.createXYLineChart("", "x", "v(x)", dataset, PlotOrientation.VERTICAL, false,
            true, true);//from   w  w  w. j a  va 2s .c o  m

    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(0, renderer);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3.0f));
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

    ValueAxis rAxis = plot.getRangeAxis();
    rAxis.setAutoRange(false);
    rAxis.setRange(new Range(-0.03, 1.03));
    ValueAxis dAxis = plot.getDomainAxis();
    dAxis.setLowerMargin(0.03);
    dAxis.setUpperMargin(0.03);

    ChartPanel chartPanel = new ChartPanel(chart, false, true, true, false, true);
    chartPanel.addChartMouseListener(new ValueFunctionMouseListener(chartPanel, criterion, parent));

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setToolTipText("Click to add/remove partial value function points");
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setMouseZoomable(false);

    plot.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairLockedOnData(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    FormLayout layout = new FormLayout("left:pref", "p, 3dlu, p");

    PanelBuilder builder = new PanelBuilder(layout);
    CellConstraints cc = new CellConstraints();
    builder.add(chartPanel, cc.xy(1, 1));
    builder.add(new ValueFunctionPointsPanel(criterion), cc.xy(1, 3));

    return builder.getPanel();
}

From source file:edu.cuny.cat.ui.SpecialistView.java

private void setupShoutPlots() {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time", "Price", dataset, true, true,
            false);//from ww w  . j  a  v  a 2  s  .c  o m
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(getContentPane().getBackground());
    xyplot = (XYPlot) chart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    xyplot.setRenderer(new XYLineAndShapeRenderer());
    final NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setTickMarkInsideLength(2.0F);
    numberaxis1.setTickMarkOutsideLength(0.0F);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(true);

    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(20, 5, 5, 20),
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Shouts"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5))));

    getContentPane().add(chartPanel, BorderLayout.CENTER);

    pack();
}

From source file:DashboardInterface.LaunchGraph.java

/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @return A panel.//from  w  ww . j  av  a 2s. c  om
 */
public JPanel createDemoPanel() {
    JFreeChart chart = createChart(null);
    ChartPanel panel = new ChartPanel(chart);
    panel.setFillZoomRectangle(false);
    panel.setMouseWheelEnabled(false);
    panel.setAutoscrolls(false);
    panel.setDomainZoomable(false);
    panel.setFocusable(false);
    return panel;
}

From source file:com.att.aro.main.FileTypesChartPanel.java

/**
 * Initializes the File Type chart.//  w w  w. jav a 2 s  . co  m
 */
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("chart.filetype.title"), null,
            rb.getString("simple.percent"), null, PlotOrientation.HORIZONTAL, false, false, false);

    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(.5f);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {

            FileTypeSummary summary = content.get(column);

            return MessageFormat.format(rb.getString("chart.filetype.tooltip"),
                    NumberFormat.getIntegerInstance().format(summary.getBytes()));
        }
    });

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    BarPainter painter = new StandardBarPainter();
    renderer.setBarPainter(painter);
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(0.1);

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, 400, ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT,
            ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:view.App.java

private void renderChart(SpreadObject obj) {
    try {//from  w  w  w. ja v a2s  .c  o  m
        jPanel3.removeAll();
        jPanel3.revalidate();
        chart = ChartFactory.createTimeSeriesChart(
                obj.getBaseStock().getTicker() + " : " + obj.getSecondStock().getTicker(), "date",
                "spread ratio", createDataset(obj), true, true, false);
    } catch (ParseException e) {
        System.out.println("    " + e.toString());
    }

    final XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 0, 0));
    renderer.setSeriesPaint(0, Color.RED);
    plot.setRenderer(renderer);

    axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(false);
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);

    jPanel3.add(chartPanel);
    jPanel3.revalidate();
}

From source file:com.att.aro.ui.view.overviewtab.FileTypesChartPanel.java

/**
 * /*from  w  w w.  j  a  v  a  2 s .c o  m*/
 * @return
 */
public JPanel layoutDataPanel() {

    setLayout(new BorderLayout());

    JFreeChart chart = initializeChart();

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, 400, ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT,
            ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    add(chartPanel, BorderLayout.CENTER);

    return this;
}

From source file:com.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java

/**
 * //from   ww w  .  j av a2 s  .co  m
 * @return
 */
public JPanel layoutDataPanel() {
    setLayout(new BorderLayout());

    JFreeChart chart = initializeChart();

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100,
            100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    add(chartPanel, BorderLayout.CENTER);

    return this;
}

From source file:com.att.aro.ui.view.overviewtab.ConnectionStatisticsChartPanel.java

public JPanel layoutDataPanel() {
    setLayout(new BorderLayout());

    JFreeChart chart = initializeChart();

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100,
            100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);//www  . jav a 2 s  . co m
    add(chartPanel, BorderLayout.CENTER);

    return this;
}