Example usage for org.jfree.chart.axis NumberTickUnit NumberTickUnit

List of usage examples for org.jfree.chart.axis NumberTickUnit NumberTickUnit

Introduction

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

Prototype

public NumberTickUnit(double size) 

Source Link

Document

Creates a new number tick unit.

Usage

From source file:ec.ui.view.AutoCorrelationsView.java

protected void onDataChange() {
    chartPanel.getChart().setTitle(ACKind.Normal == kind ? "Autocorrelations" : "Partial autocorrelations");
    NumberAxis domainAxis = (NumberAxis) chartPanel.getChart().getXYPlot().getDomainAxis();
    domainAxis.setRange(0, length);//from w  w w.  ja  v a2  s .  c  o m
    domainAxis.setTickUnit(new NumberTickUnit(length / 6));

    if (ac == DEFAULT_AUTO_CORRELATIONS) {
        chartPanel.getChart().getXYPlot().setDataset(Charts.emptyXYDataset());
    } else {
        ac.setCorrectedForMean(meanCorrection);
        ac.setKMax(length);

        double[] vals = ACKind.Normal == kind ? ac.getAC() : ac.getPAC();
        XYSeries series = new XYSeries("");
        for (int i = 0; i < vals.length; ++i) {
            series.add(i + 1, vals[i]);
        }

        XYPlot plot = chartPanel.getChart().getXYPlot();
        plot.clearRangeMarkers();
        plot.setDataset(new XYBarDataset(new XYSeriesCollection(series), 1));

        double z = 2.0d / Math
                .sqrt(ac.getUnderlyingData().getDataCount() - ac.getUnderlyingData().getMissingValuesCount());
        for (double o : new double[] { z, -z }) {
            ValueMarker marker = new ValueMarker(o);
            marker.setStroke(MARKER_STROKE);
            marker.setAlpha(MARKER_ALPHA);
            plot.addRangeMarker(marker);
        }

        onColorSchemeChange();
    }
}

From source file:com.greenpepper.confluence.macros.historic.LinearExecutionChartBuilder.java

private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(gpUtil.getText("greenpepper.historic.nodata"));

    CategoryItemRenderer renderer = plot.getRenderer();

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored())
        renderer.setSeriesPaint(index++, Color.yellow);
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId()
                    + "');";
        }//from  w ww.  j av a2s .  c  o  m
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);

    if (rangeAxis instanceof NumberAxis) {
        ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(1));
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:io.github.mzmine.util.jfreechart.ManualZoomDialog.java

private void commitChanges(ActionEvent event) {

    if (xAxisAutoRange.isSelected()) {
        xAxis.setAutoRange(true);//w  w  w. j ava2  s  . co  m
    } else {

        double lower = Double.parseDouble(xAxisRangeMin.getText());
        double upper = Double.parseDouble(xAxisRangeMax.getText());
        if (lower > upper) {
            Alert alert = new Alert(AlertType.ERROR, "Invalid " + xAxis.getLabel() + " range.");
            alert.show();
            event.consume();
            return;
        }
        xAxis.setRange(lower, upper);
    }

    if (xAxisAutoTickSize.isSelected()) {
        xAxis.setAutoTickUnitSelection(true);
    } else {
        double tickSize = Double.parseDouble(xAxisTickSize.getText());
        xAxis.setTickUnit(new NumberTickUnit(tickSize));
    }

    if (yAxisAutoRange.isSelected()) {
        yAxis.setAutoRange(true);
    } else {

        double lower = Double.parseDouble(yAxisRangeMin.getText());
        double upper = Double.parseDouble(yAxisRangeMax.getText());
        if (lower > upper) {
            Alert alert = new Alert(AlertType.ERROR, "Invalid " + yAxis.getLabel() + " range.");
            alert.show();
            event.consume();
            return;
        }
        yAxis.setRange(lower, upper);
    }

    if (yAxisAutoTickSize.isSelected()) {
        yAxis.setAutoTickUnitSelection(true);
    } else {
        double tickSize = Double.parseDouble(yAxisTickSize.getText());
        yAxis.setTickUnit(new NumberTickUnit(tickSize));
    }

}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java

private void createChart() {

    String title = "Correlation Scatter Plot  correlationCoefficient=" + nf.format(corrValue) + " N="
            + dataPoints.size();//ww w .  java2  s  .  c o  m

    corrChart = ChartFactory.createScatterPlot(title, xLabel, yLabel, null, PlotOrientation.VERTICAL, true,
            true, false);

    XYPlot plot = (XYPlot) corrChart.getPlot();

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    //        XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5));
    //           
    //        plot.addAnnotation(annotation);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.
    List<PlotPoint> plotPoints = new ArrayList<PlotPoint>(dataPoints);
    DataRange Xrange = PlotPoint.getDataRange(plotPoints, AxisType.X_AXIS);
    DataRange Yrange = PlotPoint.getDataRange(plotPoints, AxisType.Y_AXIS);

    //        Double xAbsMax = Math.max(Math.abs(Xrange.getMaxRange()), Math.abs(Xrange.getMinRange()));
    //        Double yAbsMax = Math.max(Math.abs(Yrange.getMaxRange()), Math.abs(Yrange.getMinRange()));
    //        
    //        Double maxAbsVal = Math.max(xAbsMax, yAbsMax);

    domainAxis.setAutoRangeIncludesZero(false);

    double xTick = 10.0;
    double yTick = 10.0;

    double xdist = Math.abs(Xrange.getMaxRange() - Xrange.getMinRange());
    double ydist = Math.abs(Yrange.getMaxRange() - Yrange.getMinRange());
    if (xdist < 10.0) {
        xTick = 1.0;
    }

    if (ydist < 10.0) {
        yTick = 1.0;
    }

    //        if (maxAbsVal <= 25.0) {
    //          tickUnit =5.0;
    //        }
    //        else if (maxAbsVal <= 50.0) {
    //          tickUnit = 10.0;
    //        }

    domainAxis.setTickUnit(new NumberTickUnit(xTick));
    rangeAxis.setTickUnit(new NumberTickUnit(yTick));

    //double glyphScaleFactor = (maxAbsVal*2.0)/600.0;   //assuming 600 pixels for the graph
    double xScale = xdist / 600.0;
    //double glyphScaleFactor = 1.0;
    double yScale = ydist / 600.0;

    //double adjAbsVal = Math.ceil(maxAbsVal + (glyphScaleFactor*8.0));

    //domainAxis.setRange(-maxAbsVal, maxAbsVal);
    double xMin = Xrange.getMinRange() - xScale * glyphSize;
    double xMax = Xrange.getMaxRange() + xScale * glyphSize;
    double yMin = Yrange.getMinRange() - yScale * glyphSize;
    double yMax = Yrange.getMaxRange() + yScale * glyphSize;

    domainAxis.setRange(xMin, xMax);

    //rangeAxis.setRange(-maxAbsVal, maxAbsVal);
    rangeAxis.setRange(yMin, yMax);
    Set<SampleInfo> infoSet = new HashSet<SampleInfo>();

    if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) {
        String geneName = null;
        if ((colorBy == ColorByType.IHC_EXPRESSION_X) && (ct1 != ContinuousType.GENE)) {
            logger.info("User attempted to color by ihc x on non gene continuous type.");
            //need to show validation error
            return;
        } else if ((colorBy == ColorByType.IHC_EXPRESSION_Y) && (ct2 != ContinuousType.GENE)) {
            logger.info("User attempted to color by ihc y on non gene continuous type.");
            //need to show validation error
            return;
        } else {
            if (colorBy == ColorByType.IHC_EXPRESSION_X) {
                //parse the gene name from the xLabel
                geneName = xLabel.substring(0, xLabel.indexOf('_'));
            } else if (colorBy == ColorByType.IHC_EXPRESSION_Y) {
                //parse the gene name from the yLabel
                geneName = yLabel.substring(0, yLabel.indexOf('_'));
            }
        }

        //Get the IHC data for the samples to be graphed   
        LevelOfExpressionIHCService loeService = LevelOfExpressionIHCService.getInstance();
        LossOfExpressionIHCService lossService = LossOfExpressionIHCService.getInstance();
        Set<String> sampleIds = new HashSet<String>();
        String labtrackId;
        SampleInfo info;
        for (ISPYPlotPoint corrPoint : dataPoints) {
            info = corrPoint.getSampleInfo();
            if (info != null) {
                labtrackId = corrPoint.getSampleInfo().getLabtrackId();
                sampleIds.add(labtrackId);
                infoSet.add(info);
            } else {
                logger.warn("Point id=" + corrPoint.getId() + " has no sample info. Skipping point");
            }
        }

        Collection<? extends Finding> loeFindings = loeService.getFindingsFromSampleInfo(infoSet);
        Collection<? extends Finding> lossFindings = lossService.getFindingsFromSampleInfo(infoSet);

        List<IHCFinding> findings = new ArrayList<IHCFinding>();

        for (Finding f : loeFindings) {
            findings.add((IHCFinding) f);
        }

        for (Finding f : lossFindings) {
            findings.add((IHCFinding) f);
        }

        //        Need to handle mapping names to IHC biomarker names.
        //EGFR (ok), FAK (PTK2), HER2 (ERBB2), Ki-67, P53, bcl2 (ok), p27, CYCLIN_D1 (CCND1)
        //Translate the gene names into the biomarker names 
        //used by ihc. This code should be removed once protein biomarker
        //alias is implmented.
        String ihcBiomarker = geneName;
        if (geneName.equalsIgnoreCase("PTK2")) {
            ihcBiomarker = "FAK";
            ihcBiomarkerType = IHCBiomarkerType.FAK;
        } else if (geneName.equalsIgnoreCase("ERBB2")) {
            ihcBiomarker = "HER2";
            ihcBiomarkerType = IHCBiomarkerType.HER2;
        } else if (geneName.equalsIgnoreCase("MKI67")) {
            //need to check this one
            ihcBiomarker = "Ki-67";
            ihcBiomarkerType = IHCBiomarkerType.KI67;
        } else if (geneName.equalsIgnoreCase("TP53")) {
            ihcBiomarker = "P53";
            ihcBiomarkerType = IHCBiomarkerType.P53;
        } else if (geneName.equalsIgnoreCase("Cdkn1b")) {
            ihcBiomarker = "P27";
            ihcBiomarkerType = IHCBiomarkerType.P27;
        } else if (geneName.equalsIgnoreCase("BCL2")) {
            ihcBiomarker = "BCL2";
            ihcBiomarkerType = IHCBiomarkerType.BCL2;
        } else if (geneName.equalsIgnoreCase("EGFR")) {
            ihcBiomarker = "EGFR";
            ihcBiomarkerType = IHCBiomarkerType.EGFR;
        } else if (geneName.equalsIgnoreCase("CCND1")) {
            ihcBiomarker = "CYCLIN_D1";
            ihcBiomarkerType = IHCBiomarkerType.CYCLIN_D1;
        }

        List<IHCFinding> filteredList = getIHCFindingsForBiomarker(findings, ihcBiomarker);

        //TEST Case
        //          Set<String> testIds = new HashSet<String>();
        //          testIds.add("212833");
        //          testIds.add("213152");

        //Collection<? extends Finding> loeFindings = loeService.getFindingsFromSampleIds(testIds);

        //Collection<? extends Finding> lossFindings = lossService.getFindingsFromSampleIds(sampleIds);

        ihcData = new HashMap<String, List<IHCFinding>>();
        IHCFinding loeFinding;
        List<IHCFinding> findingList;
        Specimen specimen = null;
        String patientDID = null;
        for (Finding finding : filteredList) {
            loeFinding = (IHCFinding) finding;
            specimen = loeFinding.getSpecimen();
            if ((specimen != null) && (specimen.getPatientDID() != null)) {
                patientDID = specimen.getPatientDID();
                findingList = ihcData.get(patientDID);

                if (findingList == null) {
                    findingList = new ArrayList<IHCFinding>();
                    ihcData.put(patientDID, findingList);
                }

                findingList.add(loeFinding);
            } else {
                logger.warn(
                        "loeFinding id=" + loeFinding.getId() + " has null specimen or patientDID. Skipping..");
            }

        }
        //          IHCFinding lossFinding;
        //          for (Finding finding : lossFindings) {
        //           lossFinding = (IHCFinding) finding;
        //            ihcData.put(lossFinding.getId(), lossFinding);
        //          }

    }

    createGlyphsAndAddToPlot(plot, xScale, yScale);

    // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
    //try and match the UI e9e9e9
    Paint p = new Color(233, 233, 233);

    corrChart.setBackgroundPaint(p);

    buildLegend();

}

From source file:org.matsim.contrib.analysis.vsp.traveltimedistance.TravelTimeValidationRunner.java

private void writeTravelTimeValidation(String folder, List<CarTrip> trips) {
    BufferedWriter bw = IOUtils.getBufferedWriter(folder + "/validated_trips.csv");
    XYSeriesCollection times = new XYSeriesCollection();
    XYSeriesCollection distances = new XYSeriesCollection();

    XYSeries distancess = new XYSeries("distances", true, true);
    XYSeries timess = new XYSeries("times", true, true);
    times.addSeries(timess);//from w w w .jav a 2  s.c o  m
    distances.addSeries(distancess);
    try {
        bw.append(
                "agent;departureTime;fromX;fromY;toX;toY;traveltimeActual;traveltimeValidated;traveledDistance;validatedDistance");
        for (CarTrip trip : trips) {
            if (trip.getValidatedTravelTime() != null) {
                bw.newLine();
                bw.append(trip.toString());
                timess.add(trip.getActualTravelTime(), trip.getValidatedTravelTime());
                distancess.add(trip.getTravelledDistance(), trip.getValidatedTravelDistance());
            }
        }

        bw.flush();
        bw.close();
        final JFreeChart chart2 = ChartFactory.createScatterPlot("Travel Times", "Simulated travel time [s]",
                "Validated travel time [s]", times);
        final JFreeChart chart = ChartFactory.createScatterPlot("Travel Distances",
                "Simulated travel distance [m]", "Validated travel distance [m]", distances);

        NumberAxis yAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getRangeAxis();
        NumberAxis xAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getDomainAxis();
        NumberAxis yAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis();
        NumberAxis xAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis();
        yAxisd.setUpperBound(xAxisd.getUpperBound());
        yAxis.setUpperBound(xAxis.getUpperBound());
        yAxis.setTickUnit(new NumberTickUnit(500));
        xAxis.setTickUnit(new NumberTickUnit(500));

        XYAnnotation diagonal = new XYLineAnnotation(xAxis.getRange().getLowerBound(),
                yAxis.getRange().getLowerBound(), xAxis.getRange().getUpperBound(),
                yAxis.getRange().getUpperBound());
        ((XYPlot) chart2.getPlot()).addAnnotation(diagonal);

        XYAnnotation diagonald = new XYLineAnnotation(xAxisd.getRange().getLowerBound(),
                yAxisd.getRange().getLowerBound(), xAxisd.getRange().getUpperBound(),
                yAxisd.getRange().getUpperBound());
        ((XYPlot) chart.getPlot()).addAnnotation(diagonald);

        ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveltimes" + ".png"), chart2,
                1500, 1500);
        ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveldistances.png"), chart,
                1500, 1500);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:OAT.ui.BarChartFrame.java

public void addDataset(ChartDataset dataset) {
    if (dataset == null || dataset.getSeriesCount() == 0) {
        return;//  w  ww  .j  av a  2s.c  o  m
    }

    XYPlot plot = getChart().getXYPlot();
    int i = plot.getDatasetCount();

    for (int j = 0; j < i; j++) {
        if (plot.getDataset(j).equals(dataset)) {
            //                System.out.println("eq " + i
            //                        + " " + ((ChartDataset) plot.getDataset(j)).getTitle()
            //                        + " " + dataset.getTitle());
            return;
        }
    }

    plot.setDataset(i, dataset);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    Double[] range = dataset.getAxisRange();

    //axis
    int axisId = 0;

    if (range != null) {
        //        if (range == null || range.length < 2) {
        //            plot.mapDatasetToRangeAxis(i, 0);
        //        } else {

        //scan for equal axis range, reuse if found
        boolean hasSameRange = false;

        if (range.length > 1) {
            for (int j = 1; j < plot.getRangeAxisCount(); j++) {
                Range otherRange = plot.getRangeAxis(j).getRange();

                if (otherRange != null && otherRange.getLowerBound() == range[0]
                        && otherRange.getUpperBound() == range[1]) {
                    axisId = j;
                    hasSameRange = true;
                    break;
                }
            }
        }

        if (!hasSameRange) {
            NumberAxis newAxis = new NumberAxis();

            if (range.length > 1) {
                newAxis.setAutoRange(false);
                newAxis.setRange(range[0], range[1]);
            }

            if (range.length > 2) {
                newAxis.setAutoTickUnitSelection(false, false);
                newAxis.setTickUnit(new NumberTickUnit(range[2]));
            }

            newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER);
            //                    newAxis.setAxisLinePaint(new Color(100, 0, 0));
            //                    newAxis.setLabelPaint(paints[i][0]);
            //                    newAxis.setTickLabelPaint(paints[i][0]);
            //                    newAxis.setTickMarkPaint(paints[i][0]);
            //                    newAxis.setTickLabelsVisible(true);

            axisId = plot.getRangeAxisCount();
            plot.setRangeAxis(axisId, newAxis, false);
            plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false);
        }
        //            plot.mapDatasetToRangeAxis(i, newAxisId);
    }
    plot.mapDatasetToRangeAxis(i, axisId);
    //

    //renderer
    XYLineAndShapeRenderer renderer;

    if (dataset instanceof TradeDataset) {
        renderer = new TradeRenderer();

        for (int j = 0; j < dataset.getSeriesCount(); j++) {
            renderer.setSeriesLinesVisible(j, false);
        }
    } else {

        Shape shape = Main.defaultShape;
        Paint[][] seriesPaints;
        Stroke stroke;

        if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) {
            seriesPaints = Main.greyPaints;
            stroke = Main.dottedStoke;
        } else {
            seriesPaints = Main.defaultPaints;
            stroke = Main.defaultStoke;
        }

        renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke);
    }

    plot.setRenderer(i, renderer, false);
}

From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java

public void setAxesRange(double xMin, double xMax, double xTickSize, double yMin, double yMax,
        double yTickSize) {
    NumberAxis xAxis = (NumberAxis) ticPlot.getXYPlot().getDomainAxis();
    NumberAxis yAxis = (NumberAxis) ticPlot.getXYPlot().getRangeAxis();
    xAxis.setRange(xMin, xMax);// w w w .  jav  a2 s.c o m
    xAxis.setTickUnit(new NumberTickUnit(xTickSize));
    yAxis.setRange(yMin, yMax);
    yAxis.setTickUnit(new NumberTickUnit(yTickSize));
}

From source file:info.novatec.testit.livingdoc.confluence.macros.historic.AggregationExecutionChartBuilder.java

@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) throws IOException {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    StackedBarRenderer renderer = new StackedBarRenderer(true);
    plot.setRenderer(renderer);/*from  w  ww  .j  a v a  2s  . c o m*/

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index++, Color.yellow);
    }
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new DefaultTooltipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable<?> valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0.01);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(1.0);

    if (rangeAxis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setTickUnit(new NumberTickUnit(.10));
        numberAxis.setNumberFormatOverride(PERCENT_FORMATTER);
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:info.novatec.testit.livingdoc.confluence.macros.historic.LinearExecutionChartBuilder.java

@SuppressWarnings("deprecation")
private void customizeChart(JFreeChart chart) {
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(settings.isBorder());

    TextTitle chartTitle = chart.getTitle();
    customizeTitle(chartTitle, DEFAULT_TITLE_FONT);

    addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT);
    addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata"));

    CategoryItemRenderer renderer = plot.getRenderer();

    int index = 0;
    renderer.setSeriesPaint(index++, GREEN_COLOR);
    if (settings.isShowIgnored()) {
        renderer.setSeriesPaint(index++, Color.yellow);
    }/*from  w w  w. j a v a 2s .  c o m*/
    renderer.setSeriesPaint(index, Color.red);

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setItemURLGenerator(new CategoryURLGenerator() {

        @Override
        public String generateURL(CategoryDataset data, int series, int category) {
            Comparable<?> valueKey = data.getColumnKey(category);
            ChartLongValue value = (ChartLongValue) valueKey;
            return "javascript:" + settings.getExecutionUID() + "_showExecutionResult('" + value.getId()
                    + "');";
        }
    });

    CategoryAxis domainAxis = plot.getDomainAxis();
    customizeAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    ValueAxis rangeAxis = plot.getRangeAxis();
    customizeAxis(rangeAxis);
    rangeAxis.setLowerBound(0);

    if (rangeAxis instanceof NumberAxis) {
        ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(1));
    }

    plot.setForegroundAlpha(0.8f);
}

From source file:de.citec.csra.allocation.vis.MovingChart.java

/**
 * Creates a sample chart./*from  w ww.  j a  va2  s  .c o m*/
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(null, "Time", "Resource", dataset, false, true,
            false);

    final XYPlot plot = result.getXYPlot();

    plot.addDomainMarker(this.marker);
    plot.setBackgroundPaint(new Color(0xf8f8ed));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);
    xaxis.setTickLabelsVisible(false);
    //Domain axis would show data of 60 seconds for a time
    xaxis.setFixedAutoRange(this.past + this.future); // 60 seconds
    xaxis.setVerticalTickLabels(true);
    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setAutoRangeMinimumSize(1.8);
    yaxis.setAutoRange(true);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setTickUnit(new NumberTickUnit(1));
    range.setNumberFormatOverride(new NumberFormat() {
        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return format((long) number, toAppendTo, pos);
        }

        private String getID(long number) {
            return values.entrySet().stream().filter(e -> e.equals(number)).findFirst().get().getKey();
        }

        @Override
        public StringBuffer format(long number, StringBuffer ap, FieldPosition pos) {
            String id = "N/A";
            if (number == 0) {
                id = "(Time)";
            }
            if (values.containsValue(number)) {
                for (Map.Entry<String, Long> entry : values.entrySet()) {
                    if (entry.getValue() == number) {
                        id = entry.getKey();
                        break;
                    }
                }
            }
            id = id.replaceFirst("/$", "");
            ap.append(id);
            if (id.length() > 32) {
                ap.replace(15, ap.length() - 15, "..");
            }
            return ap;
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    //      this.chart.getXYPlot().getRenderer(1).set
    //      XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) this.chart.getXYPlot().getRendererForDataset(dataset);
    return result;
}