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

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

Introduction

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

Prototype

public void setStandardTickUnits(TickUnitSource source) 

Source Link

Document

Sets the source for obtaining standard tick units for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

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

/**
 * /*from   w w  w . j  av a  2 s.  co m*/
 */
public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:gg.view.accountsbalances.GraphAccountsBalancesTopComponent.java

/**
 * Displays the accounts' balances by period
 * @param balances Accounts' balances/*from  w w  w .ja  v  a 2  s . c  o m*/
 */
private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) {
    log.info("Accounts' balances graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create the dataset (that will contain the accounts' balances)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(GraphAccountsBalancesTopComponent.class, "AccountsBalancesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // Chart color
    chart.setBackgroundPaint(jPanelAccountsBalances.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Grid lines
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // Add the series on the chart for each account displayed in the table
    for (MoneyContainer moneyContainer : balances.keySet()) {

        if (moneyContainer instanceof Account) {
            Account account = (Account) moneyContainer;
            SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>(
                    balances.get(account).keySet());

            for (SearchCriteria searchCriteria : sortedSearchCriteria) {
                if (!searchCriteria.hasAccountsFilter() || searchCriteria.getAccounts().contains(account)) {

                    dataset.addValue(balances.get(moneyContainer).get(searchCriteria), account.toString(),
                            searchCriteria.getPeriod());
                }
            }
        }
    }

    // Series' shapes
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F));
    }
    // Set the scale of the chart
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelAccountsBalances.removeAll();
    jPanelAccountsBalances.add(chartPanel, BorderLayout.CENTER);
    jPanelAccountsBalances.updateUI();

    // Display normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java

/**
 * Displays the accounts' movements balances by period
 * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted
 *//* www.  j a  va 2 s.c om*/
private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) {
    log.info("Movements' balances graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create the dataset (that will contain the movements' balances)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(GraphMovementsBalancesTopComponent.class,
                    "GraphMovementsBalancesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // Chart color
    chart.setBackgroundPaint(jPanelMovementsBalances.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Grid lines
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // Add the series on the chart
    for (MoneyContainer moneyContainer : balances.keySet()) {
        if (moneyContainer instanceof Account) {

            SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>(
                    balances.get(moneyContainer).keySet());

            for (SearchCriteria searchCriteria : sortedSearchFilters) {
                BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria);
                accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN);

                dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod());
            }
        }
    }

    // Series' shapes
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F));
    }

    // Set the scale of the chart
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelMovementsBalances.removeAll();
    jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER);
    jPanelMovementsBalances.updateUI();

    // Display normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java

/**
 * Creates a chart for the specified dataset.
 * //from  w w  w  .j  av a 2  s . c  o  m
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = null;

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (xLowerBound != null && xUpperBound != null) {
        xAxis.setLowerBound(xLowerBound);
        xAxis.setUpperBound(xUpperBound);
    } else {
        xAxis.setAutoRange(true);
    }
    xAxis.setAxisLinePaint(Color.white);
    xAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (yLowerBound != null && yUpperBound != null) {
        yAxis.setLowerBound(yLowerBound);
        yAxis.setUpperBound(yUpperBound);
    } else
        yAxis.setAutoRange(true);

    yAxis.setAxisLinePaint(Color.white);
    yAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale paintScale = null;

    if (grayPaintScale) {
        paintScale = new GrayPaintScale(minScaleValue, maxScaleValue);
    } else {
        if (scaleLowerBound != null && scaleUpperBound != null) {
            paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray);
        } else {
            paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray);
        }
        for (int i = 0; i < zRangeArray.length; i++) {
            ZRange zRange = zRangeArray[i];
            ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor());

        }
    }

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setForegroundAlpha(0.66f);

    chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    chart.removeLegend();

    NumberAxis scaleAxis = new NumberAxis(zLabel);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    if (scaleLowerBound != null && scaleUpperBound != null) {
        scaleAxis.setLowerBound(scaleLowerBound);
        scaleAxis.setUpperBound(scaleUpperBound);
    } else
        scaleAxis.setAutoRange(true);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        scaleAxis.setLabelFont(addLabelsStyle.getFont());
        scaleAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    if (blockHeight != null && blockWidth != null) {
        renderer.setBlockWidth(blockWidth.doubleValue());
        renderer.setBlockHeight(blockHeight.doubleValue());
    }

    PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.black));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(color);

    chart.addSubtitle(legend);

    //      chart.setBackgroundPaint(new Color(180, 180, 250));   
    chart.setBackgroundPaint(color);

    logger.debug("OUT");
    return chart;
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
 * Build a JPanel with a histogram plot of a desmoJ histogramAccumulate dataset
* In the case histogram.getShowTimeSpansInReport() the data values are interpreted as
* a timespan in a appropriate time unit. 
 * @param histogram      desmoJ histogramAccumulate dataset
 * @return//w w w  .j  a  va2 s .c o m
 */
private JPanel getHistogramAccumulatePlot(HistogramAccumulate histogram) {
    JFreeChart chart;
    NumberFormat formatter = NumberFormat.getInstance(locale);
    HistogramDataSetAdapter dataSet = new HistogramDataSetAdapter(histogram, locale);

    String title = histogram.getName();
    if (histogram.getDescription() != null)
        title = histogram.getDescription();
    String xLabel = dataSet.getCategoryAxisLabel();
    String yLabel = dataSet.getObservationAxisLabel();
    chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataSet, PlotOrientation.VERTICAL, false, true,
            false);
    chart.setBackgroundPaint(Color.white);

    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBaseItemLabelsVisible(true);
    StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", formatter);
    barrenderer.setBaseItemLabelGenerator(generator);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setMaximumCategoryLabelLines(4);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setNumberFormatOverride(formatter);

    return new ChartPanel(chart);
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
 * Build a JPanel with a histogram plot of a desmoJ histogram dataset
* In the case histogram.getShowTimeSpansInReport() the data values are interpreted as
* a timespan in a appropriate time unit. 
 * @param histogram      desmoJ histogram dataset
 * @return//from   w w w  . ja  v a  2 s.c  o  m
 */
private JPanel getHistogramPlot(Histogram histogram) {
    JFreeChart chart;
    NumberFormat formatter = NumberFormat.getInstance(locale);
    HistogramDataSetAdapter dataSet = new HistogramDataSetAdapter(histogram, locale);
    String title = histogram.getName();
    if (histogram.getDescription() != null)
        title = histogram.getDescription();
    String xLabel = dataSet.getCategoryAxisLabel();
    String yLabel = dataSet.getObservationAxisLabel();
    chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataSet, PlotOrientation.VERTICAL, false, true,
            false);
    chart.setBackgroundPaint(Color.white);

    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBaseItemLabelsVisible(true);
    StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", formatter);
    barrenderer.setBaseItemLabelGenerator(generator);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    //categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    categoryaxis.setMaximumCategoryLabelLines(4);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //numberaxis.setUpperMargin(0.1D);
    numberaxis.setNumberFormatOverride(formatter);

    return new ChartPanel(chart);
}

From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_vertical.java

/**
 * Creates a chart.//from   w  w  w .  java2 s . c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:correlation.and.regression.analysis.MainWindow.java

private void showCorrelationField() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries correlation = new XYSeries("Correlation Field");
    for (int i = 0; i < arr[0].countOfNumbers; i++) {
        //XYSeries tmp = new XYSeries(""+i);
        correlation.add(arr[0].getNumber(i), arr[1].getNumber(i));
        //tmp.add(arr[0].getNumber(i), arr[1].getNumber(i));
        //dataset.addSeries(tmp);
    }/*from w w  w  .  java 2 s  .  c  o m*/
    dataset.addSeries(correlation);
    XYSeries regr = StaticFunctions.drawRegressionLine(arr[0], arr[1]);
    dataset.addSeries(regr);

    XYSeries ConfidenceIntervalMax = StaticFunctions.drawConfidenceIntervalMax(arr[0], arr[1]);
    dataset.addSeries(ConfidenceIntervalMax);
    XYSeries ConfidenceIntervalMin = StaticFunctions.drawConfidenceIntervalMin(arr[0], arr[1]);
    dataset.addSeries(ConfidenceIntervalMin);

    XYSeries Confidence2IntervalMax = StaticFunctions.drawConfidence2IntervalMax(arr[0], arr[1]);
    dataset.addSeries(Confidence2IntervalMax);
    XYSeries Confidence2IntervalMin = StaticFunctions.drawConfidence2IntervalMin(arr[0], arr[1]);
    dataset.addSeries(Confidence2IntervalMin);

    XYSeries TolerantIntervalMax = StaticFunctions.drawTolerantIntervalMax(arr[0], arr[1]);
    dataset.addSeries(TolerantIntervalMax);
    XYSeries TolerantIntervalMin = StaticFunctions.drawTolerantIntervalMin(arr[0], arr[1]);
    dataset.addSeries(TolerantIntervalMin);
    JFreeChart chart = ChartFactory.createXYLineChart("Relation", "X", "Y", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesShapesVisible(4, false);
    renderer.setSeriesShapesVisible(5, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChP = new ChartPanel(chart);
    ChP.setSize(jSPanelChart.getWidth(), jSPanelChart.getHeight());
    jSPanelChart.removeAll();
    jSPanelChart.revalidate();
    jSPanelChart.add(ChP);
    jSPanelChart.repaint();
}

From source file:UserInterface.PatientRole.ManageMyVitalSignsAndFitnessRecordJPanel.java

private void createChart() {
    DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset();
    int selectedRow = viewVitalSignsJTable1.getSelectedRow();
    ArrayList<Record> recordList = patient.getRecordHistory().getRecordList();
    /*At least 2 vital sign records needed to show chart */
    if (recordList.isEmpty() || recordList.size() == 1) {
        JOptionPane.showMessageDialog(this,
                "No Fitness Record or only one fitness record found. At least 2 fitness records needed to show chart!",
                "Warning", JOptionPane.INFORMATION_MESSAGE);
        return;/*  w  ww.  j a  va  2  s.  co  m*/
    }
    for (Record record : recordList) {
        vitalSignDataset.addValue(record.getStandTime(), "StandTime", record.getDate());
        vitalSignDataset.addValue(record.getMoveTime(), "MoveTime", record.getDate());
        vitalSignDataset.addValue(record.getExcerciseTime(), "ExcerciseTime", record.getDate());
        vitalSignDataset.addValue(record.getTotalTime(), "TotalTime", record.getDate());
    }

    JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Fitness Record Chart", "Time Stamp",
            "Time(mins)", vitalSignDataset, PlotOrientation.VERTICAL, true, false, false);
    vitalSignChart.setBackgroundPaint(Color.white);
    CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot();
    vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

    CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
    vitalSignDomainAxis
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
    vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart);
    chartFrame.setVisible(true);
    chartFrame.setSize(500, 500);
}

From source file:at.ac.tuwien.inso.subcat.ui.widgets.DistributionChart.java

private void initCharts() {
    boxDataSet = new DefaultBoxAndWhiskerCategoryDataset();
    sizeDataSet = new DefaultCategoryDataset();

    // Box://from  ww w  .  j  a va 2 s . com
    NumberAxis yAxis = new NumberAxis("Values");
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    boxPlot = new CategoryPlot(boxDataSet, null, yAxis, renderer);
    drawingSupplier = boxPlot.getDrawingSupplier();

    // Bar.
    NumberAxis rangeAxis2 = new NumberAxis("Values");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    sizePlot = new CategoryPlot(sizeDataSet, null, rangeAxis2, renderer2);
    sizePlot.setDomainGridlinesVisible(true);
}