Example usage for org.jfree.chart.plot XYPlot setOrientation

List of usage examples for org.jfree.chart.plot XYPlot setOrientation

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setOrientation.

Prototype

public void setOrientation(PlotOrientation orientation) 

Source Link

Document

Sets the orientation for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart.//from   w w  w .j a v  a2 s.  c  om
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}

From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java

private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) {
    // 1. Create a single plot containing both the scatter and line
    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);//from  w ww  . j ava 2  s . c o  m
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setForegroundAlpha(0.75f);

    // 2. Setup Scatter plot
    // Create the bubble chart data, renderer, and axis
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];
    NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot
    plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator());
    plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    plotRenderer
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));

    // Set the bubble chart data, renderer, and axis into plot
    plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField));

    xPlotAxis.setAutoRangeIncludesZero(false);
    xPlotAxis.setAutoRange(false);
    double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX();
    double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX();
    double gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX());
    } else {
        xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap);
    }

    yPlotAxis.setAutoRangeIncludesZero(false);
    yPlotAxis.setAutoRange(false);
    differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY();
    differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY();
    gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY());
    } else {
        yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap);
    }

    plot.setRenderer(0, plotRenderer);
    plot.setDomainAxis(0, xPlotAxis);
    plot.setRangeAxis(0, yPlotAxis);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY);

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);

    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    // AverageY
    XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$
    horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY());
    horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY());
    lineDataset.addSeries(horizontal);

    // AverageX
    XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound());
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound());
    lineDataset.addSeries(vertical);

    plot.setDataset(1, lineDataset);
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    // 4. Setup Selection
    NumberAxis xSelectionAxis = new NumberAxis(EMPTY);
    xSelectionAxis.setTickMarksVisible(false);
    xSelectionAxis.setTickLabelsVisible(false);

    NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
    ySelectionAxis.setTickMarksVisible(false);
    ySelectionAxis.setTickLabelsVisible(false);

    XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot
    selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED);

    plot.setDataset(2, new DefaultXYZDataset2());
    plot.setRenderer(2, selectionRenderer);
    plot.setDomainAxis(2, xSelectionAxis);
    plot.setRangeAxis(2, ySelectionAxis);

    // Map the scatter to the second Domain and second Range
    plot.mapDatasetToDomainAxis(2, 0);
    plot.mapDatasetToRangeAxis(2, 0);

    // 5. Finally, Create the chart with the plot and a legend
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a Chart./*from w  ww .  ja v  a  2 s  .  c o m*/
 *
 * @param title        the title of the chart.
 * @param data         the data to use in the chart.
 * @param xAxis        the variables to use on the xAxis.
 * @param yAxis        the variables to use on the yAxis.
 * @param orientation  the orientation
 * @param itemRenderer the type of renderer to use.
 * @return the generated chart.
 */
private JFreeChart createChart(String title, XYDataset data, ValueAxis xAxis, ValueAxis yAxis,
        PlotOrientation orientation, XYItemRenderer itemRenderer, GraphDefinition def) {
    int seriesCount = data.getSeriesCount();
    for (int i = 0; i < seriesCount; i++) {
        itemRenderer.setSeriesPaint(i, def.getInlineColor(i));
        itemRenderer.setSeriesOutlinePaint(i, def.getOutlineColor(i));
    }

    XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
    plot.setOrientation(orientation);
    plot.setRenderer(itemRenderer);

    return createChart(title, plot);
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.SimpleXY_ChartPanel.java

private JFreeChart createChart(XY_PlotType type, Object userObject, Object userElement) {
    SMT_UpdateService updateService = SMT_UpdateService.getInstance();
    OMS_Collection history = updateService.getCollection();

    if ((history == null) || (history.getSize() < 2)) {
        // need at least two datapoints to this chart to make sense
        logger.severe("OMS Delta unavailable, cannot createChart(), must wait for more historical snapshots");
        MessageManager.getInstance().postMessage(
                new SmtMessage(SmtMessageType.SMT_MSG_SEVERE, "Cannot build chart without historical data"));
        return null;
    }//from ww  w. j  a v  a  2  s .  c o m

    MessageManager.getInstance()
            .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building Plot"));
    long deltaPeriod = history.getAveDeltaSeconds();

    // the primary dataset of the desired counter which will be axis1  
    XYDataset dataset1 = createDataset(history, userObject, userElement);

    // most axis are in counts (and delta counts) but utilization is in percentages
    String axisLabel = isUtilizationType() ? PortCounterAxisLabel.UTIL_AVE.getName()
            : PortCounterAxisLabel.COUNTS.getName();

    // setup the chart for the desired counter
    JFreeChart chart = ChartFactory.createTimeSeriesChart(getChartTitle(), "Time of Day", axisLabel, dataset1,
            true, true, false);

    if (isUtilizationType()) {
        chart.addSubtitle(new TextTitle(AnalysisType.getAnalysisName() + " (" + deltaPeriod + " sec. delta)"));
        //      chart.addSubtitle(new TextTitle("number of ports"));      
    } else
        chart.addSubtitle(new TextTitle(type.getName() + " Activity (" + deltaPeriod + " sec. delta)"));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.getRangeAxis().setFixedDimension(15.0);

    return chart;
}

From source file:diet.gridr.g5k.gui.GanttChart.java

/**
 * Method creating the chart//  w  w w.jav a  2s.  c o  m
 *
 * @param dataset dataset containing the data for the chart
 * @return a chart
 */
private JFreeChart createChart(XYZDataset dataset) {
    DateAxis xAxis = new DateAxis("Date");
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setDateFormatOverride(new SimpleDateFormat(durationsFormatterArray[this.visualizationDuration]));
    xAxis.setRange(Calendar.getInstance().getTime(),
            new Date(System.currentTimeMillis() + HistoryUtil.durationsTimesArray[visualizationDuration]
                    - HistoryUtil.blockWidthsArray[visualizationDuration]));
    NumberAxis yAxis = new NumberAxis("Nodes");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(true);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setRange(1, numberOfNodes);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer renderer = new XYBlockRenderer();
    LookupPaintScale paintScale = new LookupPaintScale();
    for (int i = 0; i < jobsList.get(visualizationDuration).size(); i++) {
        // String jobId = jobsList.get(visualizationDuration).get(i).getId().substring(0,jobsList.get(visualizationDuration).get(i).getId().indexOf("."));
        String jobId = jobsList.get(visualizationDuration).get(i).getParameterValue(GridJob.KEY_GRID_JOB_ID);
        int seed = Integer.parseInt(jobId);
        Random rng = new Random(seed);
        Color tempColor = Color.red;
        int red = tempColor.getRed();
        int green = tempColor.getGreen();
        int blue = tempColor.getBlue();
        int redRNG = rng.nextInt(255);
        int greenRNG = rng.nextInt(255);
        int blueRNG = rng.nextInt(255);
        if (red == redRNG && green == greenRNG && blue == blueRNG) {
            tempColor = new Color(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255));
        } else {
            tempColor = new Color(redRNG, greenRNG, blueRNG);
        }
        if (seed == 0)
            tempColor = Color.red;
        paintScale.add(new Double(i), tempColor);
    }
    renderer.setBlockWidth(HistoryUtil.blockWidthsArray[visualizationDuration]);
    renderer.setBlockAnchor(RectangleAnchor.TOP_LEFT);
    renderer.setPaintScale(paintScale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    JFreeChart chart = new JFreeChart("Gantt Chart activity for cluster " + siteName, plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    LoggingManager.log(Level.CONFIG, LoggingManager.RESOURCESTOOL, this.getClass().getName(), "createChart",
            "Chart created");
    return chart;
}

From source file:net.sourceforge.processdash.ev.ui.ScheduleBalancingDialog.java

private void addChartToPanel(JPanel panel, int gridY) {
    // create a dataset for displaying schedule data
    chartData = new ChartData();
    updateChart();//from www. j a v  a2  s.c  o  m

    // customize a renderer for displaying schedules
    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setUseYInterval(true);
    renderer.setBaseToolTipGenerator(chartData);
    renderer.setDrawBarOutline(true);

    // use an inverted, unadorned numeric Y-axis
    NumberAxis yAxis = new NumberAxis();
    yAxis.setInverted(true);
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperMargin(0);

    // use a Date-based X-axis
    DateAxis xAxis = new DateAxis();

    // create an XY plot to display the data
    XYPlot plot = new XYPlot(chartData, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(false);
    plot.setNoDataMessage(TaskScheduleDialog.resources.getString("Chart.No_Data_Message"));

    // create a chart and a chart panel
    JFreeChart chart = new JFreeChart(plot);
    chart.removeLegend();
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setInitialDelay(50);
    chartPanel.setDismissDelay(60000);
    chartPanel.setMinimumDrawHeight(40);
    chartPanel.setMinimumDrawWidth(40);
    chartPanel.setMaximumDrawHeight(3000);
    chartPanel.setMaximumDrawWidth(3000);
    chartPanel.setPreferredSize(new Dimension(300, gridY * 25));

    // add the chart to the dialog content pane
    GridBagConstraints c = new GridBagConstraints();
    c.gridy = gridY;
    c.gridwidth = 4;
    c.weightx = 2;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 0, 0, 0);
    panel.add(chartPanel, c);

    // retrieve the colors used for each chart bar, and register those
    // colors with the schedule rows so they can act as a legend
    for (int i = scheduleRows.size(); i-- > 0;) {
        ScheduleTableRow oneRow = scheduleRows.get(i);
        oneRow.addColoredIcon(renderer.lookupSeriesPaint(i));
    }
}

From source file:org.jfree.chart.demo.XYStepAreaChartDemo.java

/**
 * Change options according to settings.
 * //from   ww w. j  a  va2 s .c  o m
 * @param evt  the event.
 */
public void actionPerformed(final ActionEvent evt) {

    final Object source = evt.getSource();

    if (source == this.nullValuesCheckBox) {

        final boolean withNulls = this.nullValuesCheckBox.isSelected();
        for (int i = 0; i < TEST_DATA.length; i++) {
            Integer yVal = (Integer) TEST_DATA[i][1];
            if (withNulls && TEST_DATA[i].length > 2) {
                yVal = null;
            }
            this.xySeries.getDataItem(i).setY(yVal);
        }

    } else if (source == this.outlineCheckBox) {

        final XYPlot plot = (XYPlot) this.chartPanel.getChart().getPlot();
        ((XYStepAreaRenderer) plot.getRenderer()).setOutline(this.outlineCheckBox.isSelected());

    } else if (source == this.rangeBaseTextField) {

        final double val = Double.parseDouble(this.rangeBaseTextField.getText());
        final XYPlot plot = (XYPlot) this.chartPanel.getChart().getPlot();
        final XYStepAreaRenderer rend = (XYStepAreaRenderer) plot.getRenderer();
        rend.setRangeBase(val);

    } else if (source == this.orientationComboBox) {

        final XYPlot plot = (XYPlot) this.chartPanel.getChart().getPlot();
        if (this.orientationComboBox.getSelectedItem() == ORIENT_HORIZ) {
            plot.setOrientation(PlotOrientation.HORIZONTAL);
        } else if (this.orientationComboBox.getSelectedItem() == ORIENT_VERT) {
            plot.setOrientation(PlotOrientation.VERTICAL);
        }
    }

    this.chartPanel.repaint();
}

From source file:v800_trainer.JHistogram.java

public JPanel StartHistoHf(JCicloTronic JTronicHandle) {

    boolean Summenhisto;
    int von = 0;/* ww  w . j  a va 2 s  . co m*/
    int bis = 0;
    int num = 0;
    int selected;
    int single;
    int Gruppen = 0;
    int i = 100;
    int j = 10;
    int m = 0;
    int n = 0;
    int Linecount = 0;
    int Anzahl = 1;

    JFreeChart chart;

    double DummyData[] = new double[1];

    selected = JTronicHandle.Auswahl_Histogramm.getSelectedIndex();
    Summenhisto = JTronicHandle.Summenhistogramm_Check.isSelected();

    chart = ChartFactory.createHistogram("", "Herzfrequenz [p/min]", "Hufigkeit", new HistogramDataset(),
            PlotOrientation.HORIZONTAL, true, true, true);

    chart.setBackgroundPaint(Color.white);

    JTronicHandle.applyChartTheme(chart);

    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);

    ArrayList Bufferarray = new ArrayList();
    double Buffer;

    if (selected == 0) {
        single = 1;
    } else {
        single = 0;
        Summenhisto = false;
    } //einzelne Tour oder alle Touren

    von = Integer.parseInt(JTronicHandle.Properties.getProperty("HistovonHf", "100"));
    bis = Integer.parseInt(JTronicHandle.Properties.getProperty("HistobisHf", "200"));
    Gruppen = Integer.parseInt(JTronicHandle.Properties.getProperty("HistostepHf", "10"));
    Anzahl = (JTronicHandle.Auswahl_Histogramm.getItemCount() - 2) * single + 1; //komische Mathe;
    //wenn nur eine Tour ausgewhlt ist single = 0  und damit Anzahl =1
    // sonst single gleich 1 und die Anzahl ist ItemCont - 1
    for (j = 0; j < Anzahl; j++) {
        if (single == 1) {
            selected = j + 1; // single = 1 => Summe ist ausgewhlt und selected muss ein hher gesetz werden
        }
        if (!Summenhisto) {
            num = JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
        } else {
            num += JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
        }

        n = 0;

        if (!Summenhisto) {
            create_Start_Stop(JTronicHandle, selected); //die limits einer gezoomten Graphik ermitteln
            for (i = start; i < stop; i++) { //hier wird nun ber alle Daten gezhlt
                Buffer = (double) JTronicHandle.Statistikhandle.TourData[selected].Hf_gesZeit[i]; //aktueller Wert zwischengespeichert
                if (Buffer >= von && Buffer <= bis) {
                    Bufferarray.add(Buffer); //wenn im ges. Intervall dann in das Bufferarray
                }
            }
        } else { //Summenhist ist ausgewhlt
            for (i = 0; i < j + 1; i++) { //schlechte Schleifensteuerung i=1;i<j htte es auch getan

                create_Start_Stop(JTronicHandle, i + 1);
                for (m = start; m < stop; m++) { // Schleife ber alle Datenpunkte
                    Buffer = (double) JTronicHandle.Statistikhandle.TourData[i + 1].Hf_gesZeit[m];
                    if (Buffer >= von && Buffer <= bis) {
                        Bufferarray.add(Buffer);
                    }
                }

            }
        }

        DummyData = new double[Bufferarray.size()];

        for (i = 0; i < Bufferarray.size(); i++) {
            DummyData[i] = new Double(Bufferarray.get(i).toString());
        }

        if (!Summenhisto) {
            HistogramDataset histoHF = new HistogramDataset();
            histoHF.addSeries(
                    "" + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                            + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                            + JTronicHandle.Statistikhandle.TourData[selected].Jahr,
                    DummyData, Gruppen, (double) von, (double) bis);
            histoHF.setType(HistogramType.RELATIVE_FREQUENCY);
            plot.setDataset(Linecount, histoHF);
            plot.mapDatasetToRangeAxis(Linecount, 0);
            XYBarRenderer renderer = new XYBarRenderer();
            renderer.setDrawBarOutline(true);
            //                renderer.setShadowVisible(false);

            renderer.setSeriesPaint(0, getColour(Linecount, (int) 255 / Anzahl));

            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            plot.setRenderer(Linecount, renderer);

        }
        Linecount++;
    }

    if (Summenhisto) {
        HistogramDataset histoHF = new HistogramDataset();
        histoHF.addSeries("Summenhistogram", DummyData, Gruppen, (double) von, (double) bis);
        histoHF.setType(HistogramType.RELATIVE_FREQUENCY);

        plot.setDataset(0, histoHF);
        plot.mapDatasetToRangeAxis(0, 0);
        XYItemRenderer renderer = new XYBarRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

        plot.setRenderer(0, renderer);
    }

    chart.setPadding(padding);
    ChartPanel Panel = new ChartPanel(chart);

    return Panel;
}

From source file:v800_trainer.JHistogram.java

public JPanel StartHistoSp(JCicloTronic JTronicHandle) {

    boolean Summenhisto;
    int von = 0;//from  www.  ja v a  2s .c  o m
    int bis = 0;
    int num = 0;
    int selected;
    int single;
    int Gruppen = 0;
    int i = 100;
    int j = 10;
    int m = 0;
    int n = 0;
    int Linecount = 0;
    int Anzahl = 1;

    JFreeChart chart;

    double DummyData[] = new double[1];

    selected = JTronicHandle.Auswahl_Histogramm.getSelectedIndex();
    Summenhisto = JTronicHandle.Summenhistogramm_Check.isSelected();

    chart = ChartFactory.createHistogram("", "Geschwindigkeit [km/h]", "Hufigkeit", new HistogramDataset(),
            PlotOrientation.HORIZONTAL, true, true, true);

    chart.setBackgroundPaint(Color.white);

    JTronicHandle.applyChartTheme(chart);

    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);

    ArrayList Bufferarray = new ArrayList();
    double Buffer;

    if (selected == 0) {
        single = 1;
    } else {
        single = 0;
        Summenhisto = false;
    }

    try {
        von = Integer.parseInt(JTronicHandle.Properties.getProperty("HistovonSp", "100"));
        bis = Integer.parseInt(JTronicHandle.Properties.getProperty("HistobisSp", "200"));
        Gruppen = Integer.parseInt(JTronicHandle.Properties.getProperty("HistostepSp", "10"));
        Anzahl = (JTronicHandle.Auswahl_Histogramm.getItemCount() - 2) * single + 1;
        for (j = 0; j < Anzahl; j++) {
            if (single == 1) {
                selected = j + 1;
            }
            if (!Summenhisto) {
                num = JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
            } else {
                num += JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
            }

            n = 0;
            if (!Summenhisto) {
                create_Start_Stop(JTronicHandle, selected); //die limits einer gezoomten Graphik ermitteln

                for (i = start; i < stop; i++) {
                    Buffer = (double) JTronicHandle.Statistikhandle.TourData[selected].Geschw_gesZeit[i];
                    if (Buffer >= von && Buffer <= bis) {
                        Bufferarray.add(Buffer);
                    }
                }
            } else {
                for (i = 0; i < j + 1; i++) {
                    create_Start_Stop(JTronicHandle, i + 1);
                    for (m = start; m < stop; m++) {
                        Buffer = (double) JTronicHandle.Statistikhandle.TourData[i + 1].Geschw_gesZeit[m];
                        if (Buffer >= von && Buffer <= bis) {
                            Bufferarray.add(Buffer);
                        }

                    }
                }
            }

            DummyData = new double[Bufferarray.size()];

            for (i = 0; i < Bufferarray.size(); i++) {
                DummyData[i] = new Double(Bufferarray.get(i).toString());
            }

            if (!Summenhisto) {
                HistogramDataset histoHM = new HistogramDataset();
                histoHM.addSeries(
                        "" + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                + JTronicHandle.Statistikhandle.TourData[selected].Jahr,
                        DummyData, Gruppen, (double) von, (double) bis);
                histoHM.setType(HistogramType.RELATIVE_FREQUENCY);
                plot.setDataset(Linecount, histoHM);
                plot.mapDatasetToRangeAxis(Linecount, 0);
                XYBarRenderer renderer = new XYBarRenderer();
                renderer.setDrawBarOutline(true);

                renderer.setSeriesPaint(0, getColour(Linecount, (int) 255 / Anzahl));

                renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                plot.setRenderer(Linecount, renderer);

            }
            Linecount++;
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "StartHistoSp\nFehler: Sp " + e + " " + i + " " + j, "Achtung!",
                JOptionPane.ERROR_MESSAGE);
    }

    if (Summenhisto) {
        HistogramDataset histoHM = new HistogramDataset();
        histoHM.addSeries("Summenhistogram", DummyData, Gruppen, (double) von, (double) bis);
        histoHM.setType(HistogramType.RELATIVE_FREQUENCY);

        plot.setDataset(0, histoHM);
        plot.mapDatasetToRangeAxis(0, 0);
        XYItemRenderer renderer = new XYBarRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

        plot.setRenderer(0, renderer);
    }
    chart.setPadding(padding);
    ChartPanel Panel = new ChartPanel(chart);

    return Panel;
}

From source file:v800_trainer.JHistogram.java

public JPanel StartHistoSchrittlnge(JCicloTronic JTronicHandle) {

    boolean Summenhisto;
    int von = 0;//from  www .j  av  a2  s. c o  m
    int bis = 0;
    int num = 0;
    int selected;
    int single;
    int Gruppen = 0;
    int i = 100;
    int j = 10;
    int m = 0;
    int n = 0;
    int Linecount = 0;
    int Anzahl = 1;

    JFreeChart chart;

    double DummyData[] = new double[1];

    selected = JTronicHandle.Auswahl_Histogramm.getSelectedIndex();
    Summenhisto = JTronicHandle.Summenhistogramm_Check.isSelected();

    chart = ChartFactory.createHistogram("", "Schrittlnge [cm]", "Hufigkeit", new HistogramDataset(),
            PlotOrientation.HORIZONTAL, true, true, true);

    chart.setBackgroundPaint(Color.white);

    JTronicHandle.applyChartTheme(chart);

    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);

    ArrayList Bufferarray = new ArrayList();
    double Buffer;

    if (selected == 0) {
        single = 1;
    } else {
        single = 0;
        Summenhisto = false;
    }

    try {
        von = Integer.parseInt(JTronicHandle.Properties.getProperty("HistovonSchrittlnge", "100"));
        bis = Integer.parseInt(JTronicHandle.Properties.getProperty("HistobisSchrittlnge", "200"));
        Gruppen = Integer.parseInt(JTronicHandle.Properties.getProperty("HistostepSchrittlnge", "10"));
        Anzahl = (JTronicHandle.Auswahl_Histogramm.getItemCount() - 2) * single + 1;
        for (j = 0; j < Anzahl; j++) {
            if (single == 1) {
                selected = j + 1;
            }
            if (!Summenhisto) {
                num = JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
            } else {
                num += JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte;
            }

            n = 0;
            if (!Summenhisto) {
                create_Start_Stop(JTronicHandle, selected); //die limits einer gezoomten Graphik ermitteln

                for (i = start; i < stop; i++) {
                    Buffer = (double) JTronicHandle.Statistikhandle.TourData[selected].Schritt_lnge[i];
                    if (Buffer >= von && Buffer <= bis) {
                        Bufferarray.add(Buffer);
                    }
                }
            } else {
                for (i = 0; i < j + 1; i++) {
                    create_Start_Stop(JTronicHandle, i + 1);
                    for (m = start; m < stop; m++) {
                        Buffer = (double) JTronicHandle.Statistikhandle.TourData[i + 1].Schritt_lnge[m];
                        if (Buffer >= von && Buffer <= bis) {
                            Bufferarray.add(Buffer);
                        }

                    }

                }
            }

            DummyData = new double[Bufferarray.size()];

            for (i = 0; i < Bufferarray.size(); i++) {
                DummyData[i] = new Double(Bufferarray.get(i).toString());
            }

            if (!Summenhisto) {
                HistogramDataset histoHM = new HistogramDataset();
                histoHM.addSeries(
                        "" + JTronicHandle.Statistikhandle.TourData[selected].Tag + "."
                                + JTronicHandle.Statistikhandle.TourData[selected].Monat + "."
                                + JTronicHandle.Statistikhandle.TourData[selected].Jahr,
                        DummyData, Gruppen, (double) von, (double) bis);
                histoHM.setType(HistogramType.RELATIVE_FREQUENCY);
                plot.setDataset(Linecount, histoHM);
                plot.mapDatasetToRangeAxis(Linecount, 0);
                XYBarRenderer renderer = new XYBarRenderer();
                renderer.setDrawBarOutline(true);

                renderer.setSeriesPaint(0, getColour(Linecount, (int) 255 / Anzahl));

                renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                plot.setRenderer(Linecount, renderer);

            }
            Linecount++;
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "StartHistoSchrittlnge\nFehler: Hm " + e + " " + i + " " + j,
                "Achtung!", JOptionPane.ERROR_MESSAGE);
    }

    if (Summenhisto) {
        HistogramDataset histoHM = new HistogramDataset();
        histoHM.addSeries("Summenhistogram", DummyData, Gruppen, (double) von, (double) bis);
        histoHM.setType(HistogramType.RELATIVE_FREQUENCY);

        plot.setDataset(0, histoHM);
        plot.mapDatasetToRangeAxis(0, 0);
        XYItemRenderer renderer = new XYBarRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

        plot.setRenderer(0, renderer);
    }
    chart.setPadding(padding);
    ChartPanel Panel = new ChartPanel(chart);

    return Panel;
}