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

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

Introduction

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

Prototype

public void setUpperBound(double max) 

Source Link

Document

Sets the upper bound for the axis range, and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java

/**
 * Renders the bar chart./*  w ww  . j  a va 2  s .  com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart renderBarChart(JFreeChart chart) {

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

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

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

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.black);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.black);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.black);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.orange, 0.0f, 0.0f, Color.black);

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

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

From source file:org.cds06.speleograph.data.fileio.SpeleoFileReader.java

/**
 * Read a file with SpeleoGraph File Format.
 *
 * @param file The file to read//w  ww  . ja v a 2s  . c  o  m
 * @throws FileReadingError On error while reading the file
 */
@SuppressWarnings("HardCodedStringLiteral")
@Override
public void readFile(File file) throws FileReadingError {
    InputStreamReader streamReader;
    try {
        streamReader = new InputStreamReader(new FileInputStream(file), "UTF-8"); // NON-NLS
    } catch (UnsupportedEncodingException | FileNotFoundException e) {
        log.error("Can not access to file", e);
        throw new FileReadingError(I18nSupport.translate("error.canNotOpenFile", file.getName()),
                FileReadingError.Part.HEAD, e);
    }
    CSVReader reader = new CSVReader(streamReader, ';', '"');
    axes = new ArrayList<>();
    typeAxesChecker = new ArrayList<>();
    String[] line;
    try {
        line = reader.readNext();
    } catch (IOException e) {
        throw new FileReadingError(I18nSupport.translate("error.canNotReadFileOrEmpty"),
                FileReadingError.Part.HEAD, e);
    }
    int size, state = CHECKING;
    HeaderInformation headers = new HeaderInformation();
    DateInformation date = new DateInformation();
    headers.setDateInformation(date);
    while (line != null) {
        size = line.length;
        if (size == 0) {
            log.info("Empty line while reading file, just continue our walk.");
            continue;
        }
        String firstLineElement = line[0];
        if (firstLineElement.equals("eof"))
            break; // Force end for reading NON-NLS
        switch (state) {
        case CHECKING:
            if (!SPELEOGRAPH_FILE_HEADER.equals(firstLineElement))
                throw NOT_SPELEO_FILE;
            state = FINDING_HEADERS;
            break;
        case FINDING_HEADERS:
            if ("headers".equals(firstLineElement))
                state = READING_HEADERS; // NON-NLS
            break;
        case READING_HEADERS:
            switch (firstLineElement) {
            case "data":
                state = READING_DATA;
                break;
            case "date":
                readDateHeaderLine(date, line);
                break;
            case "axis":
                try {
                    NumberAxis axis = new NumberAxis(line[2]);
                    axis.setLowerBound((DecimalFormat.getInstance().parse(line[3])).doubleValue());
                    axis.setUpperBound(DecimalFormat.getInstance().parse(line[4]).doubleValue());
                    typeAxesChecker.add(Integer.parseInt(line[1]), new Properties(line).getBoolean("type"));
                    axes.add(Integer.parseInt(line[1]), axis);
                } catch (Exception e) {
                    log.error("Can not read axis", e);
                }
                break;
            case "chart":

                break;
            default:
                readSeriesHeaderLine(file, line, headers);
            }
            break;
        case READING_DATA:
            if (size <= 1)
                break;
            headers.read(line);
            break;
        default:
            log.info("State error in reading");
        }
        try {
            line = reader.readNext();
        } catch (IOException e) {
            log.debug("None next lines", e);
        }
    }
    Series.notifyInstanceListeners();
    log.info("File reading is ended");
}

From source file:pipeline.parameter_cell_views.FloatRangeSlider.java

@Override
protected Component getRendererOrEditorComponent(JTable table0, @NonNull Object value, boolean isSelected,
        boolean hasFocus, int row, int column, boolean rendererCalled) {
    if (currentParameter != null) {
        currentParameter.removeListener(this);
    }//from  w ww.jav a 2 s .c o  m

    currentParameter = (FloatRangeParameter) value;
    currentParameter.addGUIListener(this);

    table = table0;
    tableRow = row;

    evenTableRow = (row % 2 == 0);
    setOpaque(true);
    if (evenTableRow) {
        this.setBackground(Utils.COLOR_FOR_EVEN_ROWS);
    } else
        this.setBackground(Utils.COLOR_FOR_ODD_ROWS);
    textValueFrame.setBackground(getBackground());

    silenceUpdate = true;

    readInValuesFromParameter();

    if (currentParameter.histogram == null)
        ;// currentParameter.histogram=new XYSeries("");

    if (currentParameter.histogram instanceof XYSeries) {

        XYSeries xyData = (XYSeries) currentParameter.histogram;

        if (chart != null && chart.getXYPlot().getDataset() != null) {
            chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot());
        }

        chart = ChartFactory.createXYLineChart(null, // chart title
                null, // "Category", // domain axis label
                null, // "Value", // range axis label
                new XYSeriesCollection(xyData), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, false);

    } else if (currentParameter.histogram != null) { // assume for now it's a histogram
        if (chart != null && chart.getXYPlot().getDataset() != null) {
            chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot());
        }

        String plotTitle = "Histogram";
        String xaxis = "number";
        String yaxis = "value";
        PlotOrientation orientation = PlotOrientation.VERTICAL;
        boolean show = false;
        boolean toolTips = false;
        boolean urls = false;
        chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis,
                (IntervalXYDataset) currentParameter.histogram, orientation, show, toolTips, urls);// dataset
    } else {
        if (chart != null && chart.getXYPlot().getDataset() != null) {
            chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot());
        }
        chart = null;
    }

    if (currentParameter.histogram != null) {
        add(panelForHistogram, cForHistogram);
        final XYPlot plot = chart.getXYPlot();
        final NumberAxis domainAxis = new NumberAxis(null);
        domainAxis.setAutoRange(false);
        domainAxis.setTickLabelFont(new Font("Times", 0, 20));
        domainAxis.setLowerBound(minimum);
        domainAxis.setUpperBound(maximum);
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis(null);
        rangeAxis.setAutoRange(true);
        rangeAxis.setVisible(false);
        plot.setRangeAxis(rangeAxis);
        chart.setBackgroundPaint(Color.white);
        chart.setPadding(new RectangleInsets(0, 0, 0, 0));

        plot.setBackgroundImage(null);
        plot.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        if (chartPanel == null) {
            chartPanel = new ChartPanel(chart);
            chartPanel.addMouseListener(this);
            chartPanel.addMouseMotionListener(this);
            chartPanel.setMouseWheelEnabled(true);
            chartPanel.setMouseZoomable(false);
            chartPanel.setRangeZoomable(false);

            panelForHistogram.add(chartPanel);

        } else
            chartPanel.setChart(chart);

        chartPanel.setSize(panelForHistogram.getSize());

        ((XYPlot) chart.getPlot()).getRenderer().setSeriesStroke(0, new BasicStroke(5.0f));
        selectionRange = new IntervalMarker(currentValue0, currentValue1);
        ((XYPlot) chart.getPlot()).addDomainMarker(selectionRange);
    } else {
        remove(panelForHistogram);
        setMaximumSize(new Dimension(700, 50));
        setPreferredSize(new Dimension(700, 50));
    }

    updateDisplays();

    silenceUpdate = false;
    return this;
}

From source file:no.met.jtimeseries.MeteogramWrapper.java

private void plotPressure(GenericDataModel model, ChartPlotter plotter) {

    NumberPhenomenon pressure = model.getNumberPhenomenon(PhenomenonName.Pressure.toString());
    Color pressureColor = new Color(11, 164, 42);
    // number axis to be used for pressure plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(pressureColor);
    numberAxis.setTickLabelPaint(pressureColor);
    numberAxis.setLabel(messages.getString("parameter.pressure") + " (hPa)");
    double lowBound = 950;
    double upperBound = 1050;
    numberAxis.setLowerBound(lowBound);/*from   w ww . ja v a2 s . c  o  m*/
    numberAxis.setUpperBound(upperBound);
    double tickUnit = (upperBound - lowBound) / BACKGROUND_LINES;
    numberAxis.setTickUnit(new NumberTickUnit(tickUnit));

    PlotStyle plotStyle = new PlotStyle.Builder("Pressure (hPa)").seriesColor(pressureColor)
            .plusDegreeColor(pressureColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(1.3f))
            .numberAxis(numberAxis).build();
    plotter.addThresholdLineChart(TimeBase.SECOND, pressure, plotStyle);
}

From source file:src.gui.LifelinePanel.java

public void refreshLifeline() {
    //1. get type and context
    String dtype = diagram.getChildText("type");
    String context = diagram.getChildText("context");
    //the frame and lifeline nodes
    Element frame = diagram.getChild("frame");
    String durationStr = frame.getChildText("duration");

    float lastIntervalDuration = 0;

    //condition lifeline
    if (dtype.equals("condition")) {

        //check if the context is a action
        if (context.equals("action")) {

            //get action/operator
            Element operatorRef = diagram.getChild("action");
            Element operator = null;
            try {
                XPath path = new JDOMXPath(
                        "elements/classes/class[@id='" + operatorRef.getAttributeValue("class")
                                + "']/operators/operator[@id='" + operatorRef.getAttributeValue("id") + "']");
                operator = (Element) path.selectSingleNode(project);
            } catch (JaxenException e2) {
                e2.printStackTrace();//from ww  w  . j a va2  s  . co  m
            }

            if (operator != null) {

                //get the object (can be a parametr. literal, or object)
                Element objRef = lifeline.getChild("object");
                Element attrRef = lifeline.getChild("attribute");

                //get object class
                Element objClass = null;
                try {
                    XPath path = new JDOMXPath(
                            "elements/classes/class[@id='" + objRef.getAttributeValue("class") + "']");
                    objClass = (Element) path.selectSingleNode(project);
                } catch (JaxenException e2) {
                    e2.printStackTrace();
                }

                Element attribute = null;
                try {
                    XPath path = new JDOMXPath(
                            "elements/classes/class[@id='" + attrRef.getAttributeValue("class")
                                    + "']/attributes/attribute[@id='" + attrRef.getAttributeValue("id") + "']");
                    attribute = (Element) path.selectSingleNode(project);
                } catch (JaxenException e2) {
                    e2.printStackTrace();
                }

                //if (objClass!=null)
                Element object = null;

                //check what is this object (parameterof an action, object, literal)
                if (objRef.getAttributeValue("element").equals("parameter")) {
                    //get parameter in the action

                    try {
                        XPath path = new JDOMXPath(
                                "parameters/parameter[@id='" + objRef.getAttributeValue("id") + "']");
                        object = (Element) path.selectSingleNode(operator);
                    } catch (JaxenException e2) {
                        e2.printStackTrace();
                    }
                }

                //Boolean attribute
                if (attribute.getChildText("type").equals("1")) {

                    Element timeIntervals = lifeline.getChild("timeIntervals");

                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries("Boolean");
                    for (Iterator<Element> it1 = timeIntervals.getChildren().iterator(); it1.hasNext();) {
                        Element timeInterval = it1.next();
                        boolean insertPoint = true;

                        Element durationConstratint = timeInterval.getChild("durationConstratint");
                        Element lowerbound = durationConstratint.getChild("lowerbound");
                        Element upperbound = durationConstratint.getChild("upperbound");
                        Element value = timeInterval.getChild("value");

                        //Add for both lower and upper bound

                        //lower bound
                        float lowerTimePoint = 0;
                        try {
                            lowerTimePoint = Float.parseFloat(lowerbound.getAttributeValue("value"));
                            lastIntervalDuration = lowerTimePoint;
                        } catch (Exception e) {
                            insertPoint = false;
                        }
                        //System.out.println("    > point     x= "+ Float.toString(lowerTimePoint)+ " ,  y= "+ lowerbound.getAttributeValue("value"));
                        if (insertPoint) {
                            series.add(lowerTimePoint, (value.getText().equals("false") ? 0 : 1));
                        }

                        //upper bound
                        float upperTimePoint = 0;
                        try {
                            upperTimePoint = Float.parseFloat(upperbound.getAttributeValue("value"));
                            lastIntervalDuration = upperTimePoint;
                        } catch (Exception e) {
                            insertPoint = false;
                        }
                        //System.out.println("    > point     x= "+ Float.toString(upperTimePoint)+ " ,  y= "+ lowerbound.getAttributeValue("value"));
                        if (insertPoint && upperTimePoint != lowerTimePoint) {
                            series.add(upperTimePoint, (value.getText().equals("false") ? 0 : 1));
                        }

                    }
                    dataset.addSeries(series);

                    chart.getXYPlot().setDataset(dataset);
                    XYPlot plot = chart.getXYPlot();

                    //chart = ChartFactory.createXYStepChart(lifelineName, "time", "value", dataset, PlotOrientation.VERTICAL, false, true, false);
                    //chart = ChartFactory.createXYStepChart(attribute.getChildText("name"), "time", "value", dataset, PlotOrientation.VERTICAL, false, true, false);
                    //chart.setBackgroundPaint(Color.WHITE);

                    //XYPlot plot = (XYPlot)chart.getPlot();

                    NumberAxis domainAxis = new NumberAxis("Time");
                    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                    domainAxis.setAutoRangeIncludesZero(false);

                    //set timing ruler
                    if (durationStr.trim().equals("")) {
                        if (lastIntervalDuration > 0)
                            domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional);
                        else
                            domainAxis.setUpperBound(10.0);
                    } else {
                        try {
                            float dur = Float.parseFloat(durationStr);
                            if (dur >= lastIntervalDuration) {
                                domainAxis.setUpperBound(dur + timingRulerAdditional);
                            } else {
                                domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional);
                            }
                        } catch (Exception e) {
                            if (lastIntervalDuration > 0)
                                domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional);
                            else
                                domainAxis.setUpperBound(10.0);
                        }

                    }

                    plot.setDomainAxis(domainAxis);

                }

            }

        }
        //if this is a possible sequence of action being modeled to a condition
        else if (context.equals("general")) {

        }

    } else if (dtype.equals("state")) {

    }

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.SimpleBar.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }//ww w. ja  v a2s  .  c  o  m

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

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

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

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

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);

    if (firstAxisLB != null && firstAxisUB != null) {
        rangeAxis.setLowerBound(firstAxisLB);
        rangeAxis.setUpperBound(firstAxisUB);
    }

    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    } else
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

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

    // add
    CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}");
    renderer.setLegendItemLabelGenerator(generator);

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    if (showValueLabels) {
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        //         if(valueLabelsPosition.equalsIgnoreCase("inside")){
        //         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        //         renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        //         } else {
        //         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        //         renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        //         }

    }

    // PROVA LEGENDA      
    if (legend == true) {

        drawLegend(chart);

        /*BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0));
                
        LabelBlock titleBlock = new LabelBlock("Legend Items:",
              new Font("SansSerif", Font.BOLD, 12));
        title.setPadding(5, 5, 5, 5);
        wrapper.add(titleBlock, RectangleEdge.TOP);
                
        LegendTitle legend = new LegendTitle(chart.getPlot());
        BlockContainer items = legend.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend.setWrapper(wrapper);
                
        if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM);
        else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT);
        else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT);
        else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP);
        else legend.setPosition(RectangleEdge.BOTTOM);
                
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        chart.addSubtitle(legend);*/
    }

    int seriesN = dataset.getRowCount();

    // the order color vedctor overrides the color map!!

    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        logger.debug("color serie by SERIES_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);
            String labelName = "";
            int index = -1;
            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serieName;
                serieName = (String) seriesCaptions.get(serieName);
                index = dataset.getRowIndex(labelName);
            } else
                index = dataset.getRowIndex(serieName);

            Color color = (Color) colorMap.get(serieName);
            if (color != null) {
                //renderer.setSeriesPaint(i, color);
                renderer.setSeriesPaint(index, color);
                renderer.setSeriesItemLabelFont(i,
                        new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
                renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor());
            }
        }
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    domainAxis.setUpperMargin(0.10);
    logger.debug("OUT");
    return chart;

}

From source file:src.gui.LifelinePanel.java

/**
 * this method created and set the graph for showing the timing diagram based
 * on the variable diagram//from  w  w w.j  ava 2  s  . c om
 */
public void buildLifeLine() {

    //1. get type and context
    String dtype = diagram.getChildText("type");
    String context = diagram.getChildText("context");
    //the frame and lifeline nodes
    Element frame = diagram.getChild("frame");
    String durationStr = frame.getChildText("duration");
    lifelineName = "";
    String objectClassName = "";
    String yAxisName = "";

    float lastIntervalDuration = 0;

    //condition lifeline
    if (dtype.equals("condition")) {

        //check if the context is a action
        if (context.equals("action")) {

            //get action/operator
            Element operatorRef = diagram.getChild("action");
            Element operator = null;
            try {
                XPath path = new JDOMXPath(
                        "elements/classes/class[@id='" + operatorRef.getAttributeValue("class")
                                + "']/operators/operator[@id='" + operatorRef.getAttributeValue("id") + "']");
                operator = (Element) path.selectSingleNode(project);
            } catch (JaxenException e2) {
                e2.printStackTrace();
            }

            if (operator != null) {
                // System.out.println(operator.getChildText("name"));
                //System.out.println("Life line id "+ lifeline.getAttributeValue("id"));

                //get the object (can be a parametr. literal, or object)
                Element objRef = lifeline.getChild("object");
                Element attrRef = lifeline.getChild("attribute");

                //get object class
                Element objClass = null;
                try {
                    XPath path = new JDOMXPath(
                            "elements/classes/class[@id='" + objRef.getAttributeValue("class") + "']");
                    objClass = (Element) path.selectSingleNode(project);
                } catch (JaxenException e2) {
                    e2.printStackTrace();
                }

                Element attribute = null;
                try {
                    XPath path = new JDOMXPath(
                            "elements/classes/class[@id='" + attrRef.getAttributeValue("class")
                                    + "']/attributes/attribute[@id='" + attrRef.getAttributeValue("id") + "']");
                    attribute = (Element) path.selectSingleNode(project);
                } catch (JaxenException e2) {
                    e2.printStackTrace();
                }

                yAxisName = attribute.getChildText("name");

                //if (objClass!=null)
                Element object = null;

                //check what is this object (parameterof an action, object, literal)
                if (objRef.getAttributeValue("element").equals("parameter")) {
                    //get parameter in the action

                    try {
                        XPath path = new JDOMXPath(
                                "parameters/parameter[@id='" + objRef.getAttributeValue("id") + "']");
                        object = (Element) path.selectSingleNode(operator);
                    } catch (JaxenException e2) {
                        e2.printStackTrace();
                    }
                    String parameterStr = object.getChildText("name");

                    lifelineName = parameterStr + ":" + objClass.getChildText("name");
                    objectClassName = parameterStr + ":" + objClass.getChildText("name");
                }
                //

                //set suround border
                Border etchedBdr = BorderFactory.createEtchedBorder();
                Border titledBdr = BorderFactory.createTitledBorder(etchedBdr,
                        "lifeline(" + lifelineName + ")");
                //Border titledBdr = BorderFactory.createTitledBorder(etchedBdr, "");
                Border emptyBdr = BorderFactory.createEmptyBorder(10, 10, 10, 10);
                Border compoundBdr = BorderFactory.createCompoundBorder(titledBdr, emptyBdr);
                this.setBorder(compoundBdr);

                //Boolean attribute
                if (attribute.getChildText("type").equals("1")) {
                    lifelineName += " - " + attribute.getChildText("name");

                    Element timeIntervals = lifeline.getChild("timeIntervals");

                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries("Boolean");
                    for (Iterator<Element> it1 = timeIntervals.getChildren().iterator(); it1.hasNext();) {
                        Element timeInterval = it1.next();
                        boolean insertPoint = true;

                        Element durationConstratint = timeInterval.getChild("durationConstratint");
                        Element lowerbound = durationConstratint.getChild("lowerbound");
                        Element upperbound = durationConstratint.getChild("upperbound");
                        Element value = timeInterval.getChild("value");

                        //Add for both lower and upper bound

                        //lower bound
                        float lowerTimePoint = 0;
                        try {
                            lowerTimePoint = Float.parseFloat(lowerbound.getAttributeValue("value"));
                            lastIntervalDuration = lowerTimePoint;
                        } catch (Exception e) {
                            insertPoint = false;
                        }
                        //System.out.println("    > point     x= "+ Float.toString(lowerTimePoint)+ " ,  y= "+ lowerbound.getAttributeValue("value"));
                        if (insertPoint) {
                            series.add(lowerTimePoint, (value.getText().equals("false") ? 0 : 1));
                        }

                        //upper bound
                        float upperTimePoint = 0;
                        try {
                            upperTimePoint = Float.parseFloat(upperbound.getAttributeValue("value"));
                            lastIntervalDuration = upperTimePoint;
                        } catch (Exception e) {
                            insertPoint = false;
                        }
                        //System.out.println("    > point     x= "+ Float.toString(upperTimePoint)+ " ,  y= "+ lowerbound.getAttributeValue("value"));
                        if (insertPoint && upperTimePoint != lowerTimePoint) {
                            series.add(upperTimePoint, (value.getText().equals("false") ? 0 : 1));
                        }

                    }
                    dataset.addSeries(series);

                    //chart = ChartFactory.createXYStepChart(lifelineName, "time", "value", dataset, PlotOrientation.VERTICAL, false, true, false);
                    chart = ChartFactory.createXYStepChart(attribute.getChildText("name"), "time", "value",
                            dataset, PlotOrientation.VERTICAL, false, true, false);
                    chart.setBackgroundPaint(Color.WHITE);

                    XYPlot plot = (XYPlot) chart.getPlot();
                    plot.setBackgroundPaint(Color.WHITE);

                    NumberAxis domainAxis = new NumberAxis("Time");
                    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                    domainAxis.setAutoRangeIncludesZero(false);

                    //set timing ruler
                    if (durationStr.trim().equals("")) {
                        if (lastIntervalDuration > 0)
                            domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional);
                        else
                            domainAxis.setUpperBound(10.0);
                    } else {
                        try {
                            float dur = Float.parseFloat(durationStr);
                            if (dur >= lastIntervalDuration) {
                                domainAxis.setUpperBound(dur + timingRulerAdditional);
                            } else {
                                domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional);
                            }
                        } catch (Exception e) {
                            if (lastIntervalDuration > 0)
                                domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional);
                            else
                                domainAxis.setUpperBound(10.0);
                        }

                    }

                    plot.setDomainAxis(domainAxis);

                    String[] values = { "false", "true" };
                    //SymbolAxis rangeAxis = new SymbolAxis("Values", values);
                    SymbolAxis rangeAxis = new SymbolAxis(yAxisName, values);
                    plot.setRangeAxis(rangeAxis);

                    ChartPanel chartPanel = new ChartPanel(chart);
                    chartPanel.setPreferredSize(new Dimension(chartPanel.getSize().width, 175));

                    JLabel title = new JLabel("<html><b><u>" + objectClassName + "</u></b></html>");
                    title.setBackground(Color.WHITE);

                    this.add(title, BorderLayout.WEST);
                    this.add(chartPanel, BorderLayout.CENTER);

                }

            }

        }
        //if this is a possible sequence of action being modeled to a condition
        else if (context.equals("general")) {

        }

    } else if (dtype.equals("state")) {

    }

}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getChapterPareto(DefaultKeyedValues data, String title, String quantity, String range) {

    JFreeChart chart;//w  w  w  .  j av  a  2  s  .com

    data.sortByValues(SortOrder.DESCENDING);
    KeyedValues cummulative = DataUtilities.getCumulativePercentages(data);
    CategoryDataset dataset = DatasetUtilities.createCategoryDataset(quantity, data);

    // create the chart...
    chart = ChartFactory.createBarChart(title, // chart title
            "Chapter", // domain axis label
            range, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

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

    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();

    CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cummulative", cummulative);
    NumberAxis axis2 = new NumberAxis("Percent");
    axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
    axis2.setUpperBound(1);
    axis2.setLowerBound(0);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initRangeAxis(ChartDefinitionVO chartDefinition) {

    int axisNumber = 0;
    int datasetNumber = 0;
    for (AxisDefinitionVO axisDefinition : chartDefinition.getAxisDefinitions()) {

        // configure the axis
        NumberAxis rangeAxis = new NumberAxis(axisDefinition.getLabel());

        // set the properteis
        rangeAxis.setAutoRange(axisDefinition.isAutoRange());
        if (axisDefinition.isAutoRange()) {
            rangeAxis.setAutoRangeIncludesZero(axisDefinition.isAutoRangeIncludesZero());
        } else {//from w  w w  .j  a v a 2s.  com
            rangeAxis.setLowerBound(axisDefinition.getLowerBound());
            rangeAxis.setUpperBound(axisDefinition.getUpperBound());
        }

        if (axisDefinition.getNumberFormat() != null) {
            rangeAxis.setNumberFormatOverride(new DecimalFormat(axisDefinition.getNumberFormat())); //##0.00% / "##0.000"
        }

        getPlot().setRangeAxis(axisNumber, rangeAxis);
        getPlot().setRangeAxisLocation(axisNumber, AxisLocation.BOTTOM_OR_RIGHT);

        // initialize datasets
        for (DatasetDefinitionVO datasetDefinition : axisDefinition.getDatasetDefinitions()) {

            XYDataset dataset;
            if (DatasetType.TIME.equals(datasetDefinition.getType())) {

                // create the time series collection
                dataset = new TimeSeriesCollection();
                getPlot().setDataset(datasetNumber, dataset);

                // create the renderer
                XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setBaseShapesVisible(false);

                getPlot().setRenderer(datasetNumber, renderer);

            } else if (DatasetType.OHLC.equals(datasetDefinition.getType())) {

                // create the ohlc series collection
                dataset = new OHLCSeriesCollection();
                getPlot().setDataset(datasetNumber, dataset);

                // create the renderer
                HideableCandlestickRenderer renderer = new HideableCandlestickRenderer();
                renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator(
                        new SimpleDateFormat("dd.MM.yyyy kk:mm:ss"), NumberFormat.getInstance()));
                getPlot().setRenderer(datasetNumber, renderer);

            } else {
                throw new IllegalArgumentException("illegal dataset type " + datasetDefinition.getType());
            }

            getPlot().mapDatasetToRangeAxis(datasetNumber, axisNumber);

            // initialize series
            initSeries(datasetNumber, datasetDefinition, dataset);

            datasetNumber++;
        }

        axisNumber++;
    }
}

From source file:com.chart.SwingChart.java

/**
 * Set lower and upper limits for an ordinate
 * @param i Axis index/*from   w w  w  .  j a  v  a  2s  .c  om*/
 * @param lower Lower limit
 * @param upper Upper limit
 * @param tick Tick unit
 */
public void setOrdinateRange(int i, double lower, double upper, double tick) {
    NumberAxis e = AxesList.get(i);
    e.setAutoRange(false);
    e.setLowerBound(lower);
    e.setUpperBound(upper);
    e.setTickUnit(new NumberTickUnit(tick));

}