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

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

Introduction

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

Prototype

public CategoryAxis() 

Source Link

Document

Creates a new category axis with no label.

Usage

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

public ClientStatePanel() {

    registry = GameController.getInstance().getRegistry();
    clock = GameController.getInstance().getClock();

    setTitledBorder("Client Status");

    final CategoryAxis xAxis = new CategoryAxis();
    yAxis = new NumberAxis();
    yAxis.setTickUnit(new NumberTickUnit(1));

    // TODO: to change the colors for different kinds of events
    final ValueListShapeRenderer eventRenderer = new ValueListShapeRenderer();
    eventRenderer.setBaseOutlinePaint(Color.black);
    eventRenderer.setUseOutlinePaint(true);
    eventRenderer.setDrawOutlines(true);
    final IntervalListBarRenderer progressRenderer = new IntervalListBarRenderer();

    categoryPlot = new CategoryPlot();
    categoryPlot.setOrientation(PlotOrientation.HORIZONTAL);
    categoryPlot.setRenderer(0, eventRenderer);
    categoryPlot.setRenderer(1, progressRenderer);

    categoryPlot.setDomainAxis(xAxis);/*from  www  . j av a  2s  .  c o m*/
    categoryPlot.setRangeAxis(yAxis);

    final JFreeChart chart = new JFreeChart(categoryPlot);
    chart.setAntiAlias(false);
    chart.setBackgroundPaint(getBackground());

    categoryPlot.setForegroundAlpha(0.5F);
    categoryPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f);
    categoryPlot.setBackgroundPaint(Color.lightGray);
    categoryPlot.setRangeGridlinePaint(Color.white);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setRangeZoomable(false);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.sonar.plugins.core.charts.DistributionBarChart.java

private void configureDomainAxis(CategoryPlot plot, Font font) {
    CategoryAxis categoryAxis = new CategoryAxis();
    categoryAxis.setTickMarksVisible(true);
    categoryAxis.setTickLabelFont(font);
    categoryAxis.setTickLabelPaint(OUTLINE_COLOR);
    plot.setDomainAxis(categoryAxis);//from   w ww.  j a v  a 2  s  . com
    plot.setDomainGridlinesVisible(false);
}

From source file:org.sonar.plugins.buildstability.BuildStabilityChart.java

private void configureDomainAxis(CategoryPlot plot, String days) {
    CategoryAxis categoryAxis = new CategoryAxis();
    if (!StringUtils.isBlank(days)) {
        categoryAxis.setLabel("Last " + days + " days");
    }/*w ww.  j  a va2s.c om*/
    categoryAxis.setTickLabelsVisible(false);
    plot.setDomainAxis(categoryAxis);
    plot.setDomainGridlinesVisible(false);
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.linecharts.LineChart.java

public JFreeChart createChart() {

    logger.debug("IN");
    CategoryPlot plot = new CategoryPlot();

    NumberAxis rangeAxis = new NumberAxis("Kpi Values");
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    Color colorLabel = Color.decode("#000000");
    rangeAxis.setLabelPaint(colorLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    rangeAxis.setTickLabelPaint(colorLabel);
    plot.setRangeAxis(rangeAxis);/*from  w  w  w .  j  a  v  a 2s . c  o  m*/

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setLabelPaint(colorLabel);
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setTickLabelPaint(colorLabel);
    plot.setDomainAxis(domainAxis);

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

    //I create a line renderer 
    MyStandardCategoryItemLabelGenerator generator = null;

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
    lineRenderer.setShapesFilled(true);
    lineRenderer.setBaseItemLabelGenerator(generator);
    lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12));
    lineRenderer.setBaseItemLabelPaint(colorLabel);
    lineRenderer.setBaseItemLabelsVisible(true);

    DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line");

    for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
        String serName = (String) iterator.next();
        String labelName = "";
        int index = -1;
        index = datasetLine.getRowIndex(serName);

        Color color = Color.decode("#990200");
        lineRenderer.setSeriesPaint(index, color);
    }

    plot.setDataset(0, datasetLine);
    plot.setRenderer(0, lineRenderer);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    logger.debug("Chart created");
    TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.setTitle(title);
    TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle);
    TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle2);
    chart.removeLegend();

    chart.setBackgroundPaint(Color.white);
    logger.debug("OUT");
    return chart;
}

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java

public JFreeChart createChart() {

    logger.debug("IN");
    CategoryPlot plot = new CategoryPlot();
    IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder();
    String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName");
    NumberAxis rangeAxis = new NumberAxis(rangeAxisName);
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    Color colorLabel = Color.decode("#000000");
    rangeAxis.setLabelPaint(colorLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    rangeAxis.setTickLabelPaint(colorLabel);
    plot.setRangeAxis(rangeAxis);/*from w  w w.  j a  v  a2  s.c  om*/

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setLabelPaint(colorLabel);
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setTickLabelPaint(colorLabel);
    plot.setDomainAxis(domainAxis);

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

    //I create a line renderer 
    MyStandardCategoryItemLabelGenerator generator = null;

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
    lineRenderer.setShapesFilled(true);
    lineRenderer.setBaseItemLabelGenerator(generator);
    lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12));
    lineRenderer.setBaseItemLabelPaint(colorLabel);
    lineRenderer.setBaseItemLabelsVisible(true);

    DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line");

    for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
        String serName = (String) iterator.next();
        String labelName = "";
        int index = -1;
        index = datasetLine.getRowIndex(serName);

        Color color = Color.decode("#990200");
        lineRenderer.setSeriesPaint(index, color);
    }

    plot.setDataset(0, datasetLine);
    plot.setRenderer(0, lineRenderer);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    logger.debug("Chart created");
    TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.setTitle(title);
    TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle);
    TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle2);
    chart.removeLegend();

    chart.setBackgroundPaint(Color.white);
    logger.debug("OUT");
    return chart;
}

From source file:sanger.team16.gui.genevar.eqtl.query.SNPGeneAssocPlot.java

private JFreeChart createChart(String populationName, CategoryDataset categoryDataset, double max, double min) {
    CategoryAxis categoryaxis = new CategoryAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    //categoryaxis.setMaximumCategoryLabelWidthRatio(5F);
    //categoryaxis.setMaximumCategoryLabelLines(141);
    //categoryaxis.setCategoryMargin(450);

    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    lineandshaperenderer.setBaseShapesFilled(false);
    lineandshaperenderer.setBaseShape(ShapeUtilities.createDiamond((float) 3));
    lineandshaperenderer.setBaseSeriesVisibleInLegend(false);
    //lineandshaperenderer.setBaseLinesVisible(false);
    lineandshaperenderer.setAutoPopulateSeriesShape(false);
    lineandshaperenderer.setAutoPopulateSeriesPaint(false);
    //lineandshaperenderer.findRangeBounds(categoryDataset);

    NumberAxis numberaxis = new NumberAxis("Expression");
    numberaxis.setAutoRangeIncludesZero(false);
    //numberaxis.setRangeWithMargins(min, max);

    CategoryPlot categoryplot = new CategoryPlot(categoryDataset, categoryaxis, numberaxis,
            lineandshaperenderer);/*from w  w w .j  av  a2s . co m*/
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart jfreechart = new JFreeChart(populationName, new Font("SansSerif", 1, 14), categoryplot, true);
    return jfreechart;
}

From source file:com.redhat.thermostat.byteman.chart.swing.SwingBarChart.java

private JFreeChart createChart(Collection<PlotRecord> records) {
    // data//w ww.j  a  v  a2  s. c  om
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (PlotRecord re : records) {
        Long label = re.getPeriodStart() + ((re.getPeriodEnd() - re.getPeriodStart()) / 2);
        ds.addValue(re.getValue(), re.getCategory(), label);
    }
    // chart
    BarRenderer3D br = new StackedBarRenderer3D(cf.rendered3dXOffset, cf.rendered3dYOffset);
    ZoomablePlot plot = new ZoomablePlot(zm, ds, new CategoryAxis(), new NumberAxis(), br);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);
    // renderer
    br.setSeriesPaint(0, toColor(cf.seriesPaint0));
    br.setSeriesPaint(1, toColor(cf.seriesPaint1));
    br.setSeriesPaint(2, toColor(cf.seriesPaint2));
    br.setSeriesPaint(3, toColor(cf.seriesPaint3));
    br.setSeriesPaint(4, toColor(cf.seriesPaint4));
    br.setSeriesPaint(5, toColor(cf.seriesPaint5));
    br.setWallPaint(toColor(cf.wallPaint));
    br.setBaseItemLabelsVisible(cf.baseItemLabelsVisible);
    br.setShadowVisible(cf.shadowVisible);
    br.setItemMargin(cf.itemMargin);
    // plot
    plot.setBackgroundPaint(toColor(cf.backgroundPaint));
    plot.setBackgroundImageAlpha((float) cf.backgroundImageAlpha);
    plot.setDomainGridlinesVisible(cf.domainGridlinesVisible);
    plot.setRangeGridlinePaint(toColor(cf.rangeGridlinePaint));
    //        plot.getRangeAxis().setRange(new Range(ds.getMin(), ds.getMax() * 1.1));
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getRangeAxis().setLabel(cf.rangeAxisLabel);
    colorAxis(plot.getRangeAxis());
    colorAxis(plot.getDomainAxis());
    plot.getDomainAxis().setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI * cf.domainAxisLabelAngle));
    plot.getDomainAxis().setLowerMargin(cf.domainAxisLowerMargin);
    plot.getDomainAxis().setUpperMargin(cf.domainAxisUpperMargin);
    plot.getDomainAxis().setLabel(cf.domainAxisLabel);
    plot.setOutlineVisible(cf.outlineVisible);

    return chart;
}

From source file:org.xwiki.rendering.internal.macro.chart.source.AxisConfigurator.java

/**
 * Set the axes in the chart model./* ww  w  .  j  a v  a  2s.co m*/
 *
 * @param plotType The target plot type.
 * @param chartModel The target chart model.
 * @throws MacroExecutionException if the axes are incorrectly configured.
 */
public void setAxes(PlotType plotType, SimpleChartModel chartModel) throws MacroExecutionException {
    AxisType[] defaultAxisTypes = plotType.getDefaultAxisTypes();

    for (int i = 0; i < axisTypes.length; i++) {
        AxisType type = axisTypes[i];
        if (i >= defaultAxisTypes.length) {
            if (type != null) {
                throw new MacroExecutionException("To many axes for plot type.");
            }
            continue;
        }
        if (type == null) {
            type = defaultAxisTypes[i];
        }

        Axis axis;

        switch (type) {
        case NUMBER:
            NumberAxis numberAxis = new NumberAxis();
            axis = numberAxis;
            setNumberLimits(numberAxis, i);
            break;
        case CATEGORY:
            axis = new CategoryAxis();
            break;
        case DATE:
            DateAxis dateAxis = new DateAxis();
            axis = dateAxis;
            dateAxis.setTickMarkPosition(DateTickMarkPosition.END);
            if (axisDateFormat[i] != null) {
                try {
                    DateFormat dateFormat = new SimpleDateFormat(axisDateFormat[i],
                            localeConfiguration.getLocale());
                    dateAxis.setDateFormatOverride(dateFormat);
                } catch (IllegalArgumentException e) {
                    throw new MacroExecutionException(
                            String.format("Invalid date format [%s].", axisDateFormat[i]));
                }
            }
            setDateLimits(dateAxis, i);
            break;
        default:
            throw new MacroExecutionException(String.format("Unsupported axis type [%s]", type.getName()));
        }

        chartModel.setAxis(i, axis);
    }
}

From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java

/**
 * @return the categoryAxis/*  ww w. java 2s . c om*/
 */
private CategoryAxis getCategoryAxis() {
    if (categoryAxis == null) {
        categoryAxis = new CategoryAxis();
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.2f);
        categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(
                CategoryLabelPositions.STANDARD, new CategoryLabelPosition(RectangleAnchor.LEFT,
                        TextBlockAnchor.CENTER_LEFT, CategoryLabelWidthType.RANGE, 1.0f)));
    }
    return categoryAxis;
}

From source file:org.toobsframework.pres.chart.ChartUtil.java

public static CategoryAxis createCategoryAxis(IRequest componentRequest, DomainAxisDef categoryAxisDef,
        Map params, boolean is3D) {
    CategoryAxis categoryAxis;/* ww  w. j av a2s . c o  m*/
    if (is3D) {
        categoryAxis = new CategoryAxis3D();
    } else {
        categoryAxis = new CategoryAxis();
    }
    if (categoryAxisDef != null) {
        if (categoryAxisDef.getDomainLabel() != null) {
            categoryAxis
                    .setLabel(evaluateTextLabel(componentRequest, categoryAxisDef.getDomainLabel(), params));
            if (categoryAxisDef.getDomainLabel().getFont() != null) {
                categoryAxis.setLabelFont(getFont(categoryAxisDef.getDomainLabel(), null));
            }
            categoryAxis.setLabelPaint(getColor(categoryAxisDef.getDomainLabel().getColor()));
        }

        if (categoryAxisDef.getLabelPosition() != null) {
            Integer labelPos = domainLabelPositions.get(ParameterUtil.resolveParam(componentRequest,
                    categoryAxisDef.getLabelPosition(), params, "standard")[0]);
            if (labelPos != null) {
                switch (labelPos) {
                case DOM_LABEL_STANDARD_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
                    break;
                case DOM_LABEL_UP_45_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                    break;
                case DOM_LABEL_DOWN_45_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
                    break;
                case DOM_LABEL_UP_90_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
                    break;
                case DOM_LABEL_DOWN_90_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
                    break;
                }
            }
        }
        double domainMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getDomainMargin(), params, "0.0")[0]);
        double lowerMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getLowerMargin(), params, "0.0")[0]);
        double upperMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getUpperMargin(), params, "0.0")[0]);

        categoryAxis.setCategoryMargin(domainMargin);
        categoryAxis.setLowerMargin(lowerMargin);
        categoryAxis.setUpperMargin(upperMargin);
    }
    return categoryAxis;
}