Example usage for org.jfree.chart.axis NumberAxis setLabel

List of usage examples for org.jfree.chart.axis NumberAxis setLabel

Introduction

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

Prototype

public void setLabel(String label) 

Source Link

Document

Sets the label for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:no.met.jtimeseries.marinogram.MarinogramCurrentPlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotCurrentDirection, boolean plotCurrentSpeed) {
    ChartPlotter plotter = new ChartPlotter();
    // default setting
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");
    Color currentSpeedColor = new Color(142, 25, 131);
    Color currentDirectionColor = new Color(142, 25, 131);
    // plot style
    PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Current");
    PlotStyle plotStyle;/*from  ww w .j  a va 2  s.  c o  m*/
    NumberPhenomenon currentDirection = getOceanForecastDataModel()
            .getPhenomenen(PhenomenonName.CurrentDirection.toString(), NumberPhenomenon.class);
    NumberPhenomenon currentSpeed = getOceanForecastDataModel()
            .getPhenomenen(PhenomenonName.CurrentSpeed.toString(), NumberPhenomenon.class);
    if (currentSpeed == null || currentDirection == null) {
        return null;
    }
    currentSpeed = currentSpeed.scaling(100);
    double tick = (currentSpeed.getMaxValue() - currentSpeed.getMinValue()) / 2;
    tick = Math.ceil(tick / 10) * 10;
    double lowBound = Math.floor(currentSpeed.getMinValue() / (tick)) * (tick);
    //The minimum scale is 0
    lowBound = lowBound < 0 ? 0 : lowBound;
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 4;

    // reference the range axis
    NumberAxis leftNumberAxis = new NumberAxis();
    leftNumberAxis.setLabel(messages.getString("parameter.current") + " (cm/s)");
    leftNumberAxis.setLabelPaint(currentSpeedColor);
    leftNumberAxis.setTickLabelPaint(currentSpeedColor);
    leftNumberAxis.setLowerBound(lowBound);
    leftNumberAxis.setUpperBound(upperBound);
    leftNumberAxis.setTickUnit(new NumberTickUnit(tick));

    NumberAxis rightNumberAxis = new NumberAxis();
    rightNumberAxis.setLabel(messages.getString("label.knots"));
    rightNumberAxis.setLabelPaint(currentSpeedColor);
    rightNumberAxis.setTickLabelPaint(currentSpeedColor);
    lowBound = lowBound / 100.0 / KNOT;
    upperBound = upperBound / 100.0 / KNOT;
    rightNumberAxis.setLowerBound(lowBound);
    rightNumberAxis.setUpperBound(upperBound);
    rightNumberAxis.setTickUnit(new NumberTickUnit(tick / 100.0 / KNOT));
    NumberFormat formatter = new DecimalFormat("#0.00");
    rightNumberAxis.setNumberFormatOverride(formatter);

    List<Date> shortTermTimeList = this.getShortTermTime(currentDirection.getTime().get(0));

    //set thte plot current speed color to be transparent if show current speed is false
    if (!plotCurrentSpeed) {
        currentSpeedColor = new Color(0, 0, 0, 0);
    }

    // plot style
    BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2.0f,
            new float[] { 2.0f, 6.0f }, 0.0f);
    plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(dottedStroke)
            .seriesColor(currentSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build();

    //Draw the current direction even if plotCurrentSpeed is false (but with transparent in such a case)
    //for the purpose to keep the same background grid and tick label on the y-axis 
    //no matter the wave height is shown or not
    plotter.addLineChart(TimeBase.SECOND, currentSpeed, plotStyle);

    plotter.getPlot().setRangeAxis(1, rightNumberAxis);
    plotter.getPlot().setOutlineVisible(true);

    Date minDate = shortTermTimeList.get(0);
    Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // invisible domain axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
    // add markers
    plotter.addDomainMarkers(shortTermTimeList, timezone, locale);

    if (plotCurrentDirection) {
        List<Date> symbolTimes = Utility.filterMinimumHourInterval(currentDirection.getTime(), 2, 1);
        InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes);
        currentDirection.filter(symbolTimesFilter);
        currentSpeed = null;
        if (plotCurrentSpeed) {
            currentSpeed = getOceanForecastDataModel().getPhenomenen(PhenomenonName.CurrentSpeed.toString(),
                    NumberPhenomenon.class);
            currentSpeed.filter(symbolTimesFilter);
            currentSpeed = currentSpeed.scaling(1 / 100.0 / KNOT);
        }

        plotStyle = currentStyleBuilder.seriesColor(currentDirectionColor).build();
        plotter.addArrowDirectionPlot(currentDirection, currentSpeed, 2, plotStyle);
    }
    plotter.getPlot().setRangeZeroBaselineVisible(false);

    return plotter.getPlot();

}

From source file:no.met.jtimeseries.marinogram.MarinogramWindPlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotWindDirection, boolean plotWindSpeed) {
    ChartPlotter plotter = new ChartPlotter();
    // default setting
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");
    Color windSpeedColor = new Color(0, 0, 0);
    Color windDirectionColor = new Color(0, 0, 0);
    // plot style
    PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Wind");
    PlotStyle plotStyle;/*from   w  w  w. j a  va2s  . co m*/
    NumberPhenomenon windDirection = getLocationForecastDataModel()
            .getPhenomenen(PhenomenonName.WindDirectionDegree.toString(), NumberPhenomenon.class);
    NumberPhenomenon windSpeed = getLocationForecastDataModel()
            .getPhenomenen(PhenomenonName.WindSpeedMPS.toString(), NumberPhenomenon.class);
    if (windSpeed == null || windDirection == null) {
        return null;
    }

    double tick = (windSpeed.getMaxValue() - windSpeed.getMinValue()) / 3;
    tick = Math.ceil(tick);
    double lowBound = Math.floor(windSpeed.getMinValue() / (tick)) * (tick);
    //The minimum scale is 0
    lowBound = lowBound < 0 ? 0 : lowBound;
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 6;

    // reference the range axis
    NumberAxis leftNumberAxis = new NumberAxis();
    leftNumberAxis.setLabel(messages.getString("parameter.wind") + " (m/s)");
    leftNumberAxis.setLabelPaint(windSpeedColor);
    leftNumberAxis.setTickLabelPaint(windSpeedColor);
    //int tickUnit = (int) Math.ceil((upperBound - lowBound) / 6);
    leftNumberAxis.setTickUnit(new NumberTickUnit(tick));
    leftNumberAxis.setLowerBound(lowBound);
    leftNumberAxis.setUpperBound(upperBound);

    NumberAxis rightNumberAxis = new NumberAxis();
    rightNumberAxis.setLabel(messages.getString("label.knots"));
    rightNumberAxis.setLabelPaint(windSpeedColor);
    rightNumberAxis.setTickLabelPaint(windSpeedColor);
    lowBound = lowBound / KNOT;
    upperBound = upperBound / KNOT;
    rightNumberAxis.setLowerBound(lowBound);
    rightNumberAxis.setUpperBound(upperBound);
    rightNumberAxis.setTickUnit(new NumberTickUnit(tick / KNOT));
    NumberFormat formatter = new DecimalFormat("#0.0");
    rightNumberAxis.setNumberFormatOverride(formatter);

    List<Date> shortTermTimeList = this.getShortTermTime(windDirection.getTime().get(0));

    // set thte plot current speed color to be transparent if show current
    // speed is false
    if (!plotWindSpeed) {
        windSpeedColor = new Color(0, 0, 0, 0);
    }

    // plot style
    plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f))
            .seriesColor(windSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build();

    // Draw the current direction even if plotCurrentSpeed is false (but
    // with transparent in such a case)
    // for the purpose to keep the same background grid and tick label on
    // the y-axis
    // no matter the wave height is shown or not
    plotter.addLineChart(TimeBase.SECOND, windSpeed, plotStyle);

    plotter.getPlot().setRangeAxis(1, rightNumberAxis);
    plotter.getPlot().setOutlineVisible(true);

    Date minDate = shortTermTimeList.get(0);
    Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // invisible domain axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
    // add markers
    plotter.addDomainMarkers(shortTermTimeList, timezone, locale);

    if (plotWindDirection) {
        List<Date> symbolTimes = Utility.filterMinimumHourInterval(windDirection.getTime(), 2, 1);
        InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes);
        windDirection.filter(symbolTimesFilter);
        windSpeed = null;
        if (plotWindSpeed) {
            windSpeed = getLocationForecastDataModel().getPhenomenen(PhenomenonName.WindSpeedMPS.toString(),
                    NumberPhenomenon.class);
            windSpeed.filter(symbolTimesFilter);
            windSpeed = windSpeed.scaling(1 / KNOT);
        }

        plotStyle = currentStyleBuilder.seriesColor(windDirectionColor).build();
        // when plot wind direction, the arrow should be rotated 180 degree
        windDirection = windDirection.transform(180);
        plotter.addArrowDirectionPlot(windDirection, windSpeed, 2, plotStyle);
        // transform back after plot
        windDirection = windDirection.transform(180);
    }
    plotter.getPlot().setRangeZeroBaselineVisible(false);

    return plotter.getPlot();

}

From source file:org.cytoscape.dyn.internal.graphMetrics.GenerateChart.java

public JFreeChart generateTimeSeries() {

    dataset = new XYSeriesCollection();
    XYSeries[] attributeSeries = new XYSeries[(selectedNodes.size() + selectedEdges.size())
            * (checkedAttributes.size() + edgeCheckedAttributes.size())];
    int j = 0;/*from   w w w .  j ava2  s. c om*/
    /*creating dataseries for each node and its checked attribute and
    adding it to the dataset*/
    for (CyNode node : selectedNodes) {
        // System.out.println(checkedAttributes.size());
        for (int i = 0; i < checkedAttributes.size(); i++) {
            attributeSeries[j] = new XYSeries(dynamicNetwork.getNodeLabel(node) + checkedAttributes.get(i),
                    false, true);
            // System.out.println(dynamicNetwork.getDynAttribute(node,
            // checkedAttributes.get(i)).getKey().getColumn());

            for (DynInterval<T> interval : dynamicNetwork.getDynAttribute(node, checkedAttributes.get(i))
                    .getIntervalList()) {
                // System.out.println(interval.getOnValue());
                double value;
                if (interval.getOnValue() instanceof Double)
                    value = (Double) interval.getOnValue();
                else
                    value = ((Integer) interval.getOnValue()).doubleValue();
                // System.out.println(value);
                attributeSeries[j].add(interval.getStart(), value);
                attributeSeries[j].add(interval.getEnd(), value);
                //System.out.println("interval start ="+interval.getStart());
                //System.out.println("interval end ="+interval.getEnd());
                //System.out.println("--------");
            }
            dataset.addSeries(attributeSeries[j++]);
        }
    }
    /*creating dataseries for each edge and its checked attribute and
    adding it to the dataset*/
    for (CyEdge edge : selectedEdges) {
        // System.out.println(checkedAttributes.size());
        for (int i = 0; i < edgeCheckedAttributes.size(); i++) {
            attributeSeries[j] = new XYSeries(dynamicNetwork.getEdgeLabel(edge) + edgeCheckedAttributes.get(i),
                    false, true);
            // System.out.println(dynamicNetwork.getDynAttribute(node,
            // checkedAttributes.get(i)).getKey().getColumn());

            for (DynInterval<T> interval : dynamicNetwork.getDynAttribute(edge, edgeCheckedAttributes.get(i))
                    .getIntervalList()) {
                // System.out.println(interval.getOnValue());
                double value;
                if (interval.getOnValue() instanceof Double)
                    value = (Double) interval.getOnValue();
                else if (interval.getOnValue() instanceof Integer)
                    value = ((Integer) interval.getOnValue()).doubleValue();
                else if (interval.getOnValue() instanceof Short)
                    value = ((Short) interval.getOnValue()).doubleValue();
                else
                    value = ((Long) interval.getOnValue()).doubleValue();
                // System.out.println(value);
                attributeSeries[j].add(interval.getStart(), value);
                attributeSeries[j].add(interval.getEnd(), value);

            }
            dataset.addSeries(attributeSeries[j++]);
        }
    }

    String title = "Dynamic Graph Metrics";
    String xAxisLabel = "Time";
    String yAxisLabel = "Centrality Value";
    JFreeChart chart = ChartFactory.createXYStepChart(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, // legend
            true, // tooltips
            false // urls
    );

    NumberAxis xaxis = new NumberAxis();
    xaxis.setAutoRangeMinimumSize(1.0);
    xaxis.setLabel("Time");
    chart.getXYPlot().setDomainAxis(xaxis);
    NumberAxis yaxis = new NumberAxis();
    yaxis.setAutoRangeIncludesZero(true);
    yaxis.setLabel("Centrality/Attribute Value");
    chart.getXYPlot().setRangeAxis(yaxis);
    chart.setBackgroundPaint(Color.white);
    //chart.setPadding(new RectangleInsets(20,20,20,20));
    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setDomainGridlinePaint(Color.gray);
    chart.getXYPlot().setRangeGridlinePaint(Color.gray);
    return chart;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.AbstractTimeChartStrategy.java

/**
 *
 * @return//  w  w  w .ja v  a  2s  .c  o m
 */
public NumberAxis getRangeAxis() {
    NumberAxis valueaxis = new NumberAxis();
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.25D);
    valueaxis.setLabel(this.getYAxisLabel());
    return valueaxis;
}

From source file:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java

private void plotTemperature(ChartPlotter plotter, NumberPhenomenon temperature, BasicStroke stroke,
        Color color, String label, boolean isThresholdLine) {
    // number axis to be used for wind speed plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(color);/*  ww  w. ja  v  a2s .c o m*/
    numberAxis.setTickLabelPaint(color);
    numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)");
    PlotStyle plotStyle = new PlotStyle.Builder(label).ticks(6).stroke(stroke).seriesColor(color)
            .plusDegreeColor(color).labelColor(new Color(240, 28, 28)).spline(SplineStyle.HYBRID)
            .numberAxis(numberAxis).build();

    if (isThresholdLine)
        plotter.addThresholdLineChart(TimeBase.SECOND, temperature, plotStyle);
    else
        plotter.addLineChart(TimeBase.SECOND, temperature, plotStyle);
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.tasks.ChromatogramViewLoaderWorker.java

private void configurePlot(XYPlot plot, RTUnit rtAxisUnit) {
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(new RTNumberFormatter(rtAxisUnit));
    domainAxis.setLabel("RT[" + rtAxisUnit.name().toLowerCase() + "]");
    plot.setRangeZeroBaselineVisible(true);
    plot.setDomainZeroBaselineVisible(false);
    domainAxis.setAutoRange(true);/*from w w  w.  ja v a2  s. c  o m*/
    domainAxis.setAutoRangeIncludesZero(false);
    ((NumberAxis) plot.getRangeAxis()).setAutoRange(true);
    ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(true);
    Logger.getLogger(getClass().getName()).info("Adding chart");
    plot.setBackgroundPaint(Color.WHITE);
}

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

/**
 * Initializes the Panel for Proper Session Termination plot.
 *//*www  .j  a va 2 s .  com*/
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.sessionoverview.title"), null, null,
            createDataset(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(1.0f);
    domainAxis.setMaximumCategoryLabelLines(2);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(rb.getString("analysisresults.percentage"));
    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));

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

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

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String sessionInfo = "";
            switch (arg2) {
            case SESSION_TERMINATION:
                sessionInfo = rb.getString("tooltip.sessionTermination");
                break;
            case SESSION_TIGHT_CONN:
                sessionInfo = rb.getString("tooltip.sessionTightConn");
                break;
            case SESSION_BURST:
                sessionInfo = rb.getString("tooltip.sessionBurst");
                break;
            case SESSION_LONG_BURST:
                sessionInfo = rb.getString("tooltip.sessionLongBurst");
                break;
            }

            return sessionInfo;
        }
    });

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

    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);
    this.add(chartPanel, BorderLayout.CENTER);
}

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

/**
 * Initializes the Main panel and its various components.
 *//* w  ww .j  a va  2s .  com*/
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.traceoverview.title"), null, null,
            createDataset(null), PlotOrientation.HORIZONTAL, false, true, 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 valueRangeAxis = plot.getDomainAxis();
    valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    valueRangeAxis.setMaximumCategoryLabelLines(2);
    valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(rb.getString("analysisresults.percentile"));
    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));

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

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

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);
    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String traceInfo = "";
            switch (arg2) {
            case TRACE_AVERAGE:
                traceInfo = rb.getString("tooltip.traceAnalysis.avg");
                break;
            case TRACE_ENERGY:
                traceInfo = rb.getString("tooltip.traceAnalysis.engy");
                break;
            case TRACE_OVERHEAD:
                traceInfo = rb.getString("tooltip.traceAnalysis.ovrhd");
                break;
            }

            return traceInfo;
        }
    });

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

    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);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:uk.ac.lkl.cram.ui.chart.FeedbackChartMaker.java

/**
 * Create a chart from the provided category dataset
 * @return a Chart that can be rendered in a ChartPanel
 *///  w ww .ja va 2 s .c  o  m
@Override
protected JFreeChart createChart() {
    //Create a vertical bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //Get the font from the platform UI
    Font chartFont = UIManager.getFont("Label.font");
    //Get the plot from the chart
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //Get the renderer from the plot
    BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
    //Set the rendered to use a standard bar painter (nothing fancy)
    barRenderer.setBarPainter(new StandardBarPainter());
    //Set the colours for the bars
    barRenderer.setSeriesPaint(0, PEER_ONLY_COLOR);
    barRenderer.setSeriesPaint(1, TEL_COLOR);
    barRenderer.setSeriesPaint(2, TUTOR_COLOR);
    //Set the tooltip to be series, category and value
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(
            "<html><center>{0} ({2} hours)<br/>Double-click for more</center></html>",
            NumberFormat.getInstance()));
    //Get the category axis (that's the X-axis in this case)
    CategoryAxis categoryAxis = plot.getDomainAxis();
    //Set the font for rendering the labels on the x-axis to be the platform default
    categoryAxis.setLabelFont(chartFont);
    //Hide the tick marks and labels for the x-axis
    categoryAxis.setTickMarksVisible(false);
    categoryAxis.setTickLabelsVisible(false);
    //Set the label for the x-axis
    categoryAxis.setLabel("Feedback to individuals or group");
    //Get the number axis (that's the Y-axis in this case)
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    //Use the same font as the x-axis
    numberAxis.setLabelFont(chartFont);
    //Set the label for the vertical axis
    numberAxis.setLabel("Hours");
    return chart;
}

From source file:edu.cudenver.bios.chartsvc.resource.LegendResource.java

private XYPlot buildScatterPlot(Chart chart) throws ResourceException {
    // the first series is treated as the x values
    if (chart.getSeries() == null || chart.getSeries().size() <= 0)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified");

    // create the jfree chart series
    XYSeriesCollection chartData = new XYSeriesCollection();
    // use a spline renderer to make the connecting lines smooth
    XYSplineRenderer rend = new XYSplineRenderer();

    int seriesIdx = 0;
    for (Series series : chart.getSeries()) {
        XYSeries xySeries = new XYSeries(series.getLabel());

        List<Double> xList = series.getXCoordinates();
        List<Double> yList = series.getYCoordinates();
        if (xList != null && yList != null && xList.size() == yList.size()) {
            for (int i = 0; i < xList.size(); i++) {
                xySeries.add(xList.get(i), yList.get(i));
            }/* w  ww .  ja va 2s  .  co m*/
        }

        // set the line style
        rend.setSeriesPaint(seriesIdx, Color.BLACK);
        if (seriesIdx > 0) {
            rend.setSeriesStroke(seriesIdx, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { (float) seriesIdx, (float) 2 * seriesIdx }, 0.0f));
        }
        // add the series to the data set
        chartData.addSeries(xySeries);
        seriesIdx++;
    }

    // turn off shapes displayed at each data point to make a smooth curve
    rend.setBaseShapesVisible(false);

    // Create the line chart
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    if (chart.getXAxis() != null) {
        Axis xAxisSpec = chart.getXAxis();
        xAxis.setLabel(xAxisSpec.getLabel());
        if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) {
            xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax());
        }
    }
    NumberAxis yAxis = new NumberAxis();
    if (chart.getYAxis() != null) {
        Axis yAxisSpec = chart.getYAxis();
        yAxis.setLabel(chart.getYAxis().getLabel());
        if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) {
            xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax());
        }
    }
    XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    return plot;
}