Package org.jfree.chart.plot

Examples of org.jfree.chart.plot.CombinedDomainCategoryPlot


    /**
     * Some checks for cloning.
     */
    public void testCloning() {
        CombinedDomainCategoryPlot plot1 = createPlot();
        CombinedDomainCategoryPlot plot2 = null;
        try {
            plot2 = (CombinedDomainCategoryPlot) plot1.clone();
        }
        catch (CloneNotSupportedException e) {
            System.err.println("Failed to clone.");
        }
        assertTrue(plot1 != plot2);
        assertTrue(plot1.getClass() == plot2.getClass());
        assertTrue(plot1.equals(plot2));
    }
View Full Code Here


    /**
     * Serialize an instance, restore it, and check for equality.
     */
    public void testSerialization() {
        CombinedDomainCategoryPlot plot1 = createPlot();
        CombinedDomainCategoryPlot plot2 = null;
        try {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(plot1);
            out.close();
View Full Code Here

    /**
     * Check that only one chart change event is generated by a change to a
     * subplot.
     */
    public void testNotification() {
        CombinedDomainCategoryPlot plot = createPlot();
        JFreeChart chart = new JFreeChart(plot);
        chart.addChangeListener(this);
        CategoryPlot subplot1 = (CategoryPlot) plot.getSubplots().get(0);
        NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();
        yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());
        assertEquals(1, this.events.size());

        // a redraw should NOT trigger another change event
View Full Code Here

            dataset2, null, rangeAxis2, renderer2
        );
        subplot2.setDomainGridlinesVisible(true);

        CategoryAxis domainAxis = new CategoryAxis("Category");
        CombinedDomainCategoryPlot plot
            = new CombinedDomainCategoryPlot(domainAxis);
        plot.add(subplot1, 2);
        plot.add(subplot2, 1);
        return plot;

    }
View Full Code Here

    DefaultCategoryDataset datasetLineSecondAxis=(DefaultCategoryDataset)datasets.getDatasets().get("2-line");

    // create the two subplots
    CategoryPlot subPlot1 = new CategoryPlot();
    CategoryPlot subPlot2 = new CategoryPlot();
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    subPlot1.setDataset(0,datasetBarFirstAxis);
    subPlot2.setDataset(0,datasetBarSecondAxis);

    subPlot1.setDataset(1,datasetLineFirstAxis);
    subPlot2.setDataset(1,datasetLineSecondAxis);

    // localize numbers on y axis
        NumberFormat nf = (NumberFormat) NumberFormat.getNumberInstance(locale);

   
    // Range Axis 1
    NumberAxis rangeAxis = new NumberAxis(getValueLabel());
    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);
    subPlot1.setRangeAxis(rangeAxis);
    if(rangeIntegerValues==true){
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits())
    }

    // Range Axis 2
    NumberAxis rangeAxis2 = new NumberAxis(secondAxisLabel);
    rangeAxis2.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2.setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2.setUpperMargin(0.10);
        rangeAxis2.setNumberFormatOverride(nf);   
    subPlot2.setRangeAxis(rangeAxis2);
    if(rangeIntegerValues==true){
      rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits())
    }

    // Category Axis
    CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel());
    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);
    plot.setDomainAxis(domainAxis);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // Add subplots to main plot
    plot.add(subPlot1, 1);
    plot.add(subPlot2, 2);

    MyStandardCategoryItemLabelGenerator generator=null;

    // value labels and additional values are mutually exclusive
    if(showValueLabels==true)additionalLabels=false;

    if(additionalLabels){
      generator = new MyStandardCategoryItemLabelGenerator(catSerLabels,"{1}", NumberFormat.getInstance());
    }

//    Create Renderers!
    CategoryItemRenderer barRenderer1=new BarRenderer();
    CategoryItemRenderer barRenderer2=new BarRenderer();
    LineAndShapeRenderer lineRenderer1=(useLinesRenderers==true) ? new LineAndShapeRenderer() : null;
    LineAndShapeRenderer lineRenderer2=(useLinesRenderers==true) ? new LineAndShapeRenderer() : null;

    subPlot1.setRenderer(0,barRenderer1);
    subPlot2.setRenderer(0,barRenderer2);

    if(useLinesRenderers==true){
      subPlot1.setRenderer(1,lineRenderer1);
      subPlot2.setRenderer(1,lineRenderer2);

      // no shapes for line_no_shapes  series
      for (Iterator iterator = lineNoShapeSeries1.iterator(); iterator.hasNext();) {
        String ser = (String) iterator.next();
        // if there iS a abel associated search for that
        String label=null;
        if(seriesLabelsMap!=null){
          label=(String)seriesLabelsMap.get(ser);
        }
        if(label==null)label=ser;
        int index=datasetLineFirstAxis.getRowIndex(label);
        if(index!=-1){
          lineRenderer1.setSeriesShapesVisible(index, false);
        }
      }
      for (Iterator iterator = lineNoShapeSeries2.iterator(); iterator.hasNext();) {
        String ser = (String) iterator.next();
        // if there iS a abel associated search for that

        String label=null;
        if(seriesLabelsMap!=null){
          label=(String)seriesLabelsMap.get(ser);
        }
        if(label==null)label=ser;
        int index=datasetLineSecondAxis.getRowIndex(label);
        if(index!=-1){
          lineRenderer2.setSeriesShapesVisible(index, false);
        }
      }

    }

    // add tooltip if enabled
    if(enableToolTips){
      MyCategoryToolTipGenerator generatorToolTip=new MyCategoryToolTipGenerator(freeToolTips, seriesTooltip, categoriesTooltip, seriesCaptions);
      barRenderer1.setToolTipGenerator(generatorToolTip);
      barRenderer2.setToolTipGenerator(generatorToolTip);
      if(useLinesRenderers){
        lineRenderer1.setToolTipGenerator(generatorToolTip);
        lineRenderer2.setToolTipGenerator(generatorToolTip);       
      }
    }

    subPlot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    subPlot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // COnfigure renderers: I do in extensive way so will be easier to add customization in the future

    if(maxBarWidth!=null){
      ((BarRenderer)barRenderer1).setMaximumBarWidth(maxBarWidth.doubleValue());
      ((BarRenderer)barRenderer2).setMaximumBarWidth(maxBarWidth.doubleValue());
    }


    // Values or addition Labels for first BAR Renderer
    if(showValueLabels){
      barRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
      barRenderer1.setBaseItemLabelsVisible(true);
      barRenderer1.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
      barRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());

      barRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(
          ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

      barRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
          ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

      barRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
      barRenderer2.setBaseItemLabelsVisible(true);
      barRenderer2.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
      barRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());

      barRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(
          ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

      barRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
          ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

    }
    else if(additionalLabels){
      barRenderer1.setBaseItemLabelGenerator(generator);
      barRenderer2.setBaseItemLabelGenerator(generator);

      double orient=(-Math.PI / 2.0);
      if(styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")){
        orient=0.0;
      }

      barRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
      barRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
      barRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
      barRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

    }

    // Values or addition Labels for line Renderers if requested
    if(useLinesRenderers==true){
      if(showValueLabels){
        lineRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        lineRenderer1.setBaseItemLabelsVisible(true);
        lineRenderer1.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        lineRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());
        lineRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
        lineRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
        lineRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        lineRenderer2.setBaseItemLabelsVisible(true);
        lineRenderer2.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        lineRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());
        lineRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
        lineRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

      }
      else if(additionalLabels){
        lineRenderer1.setBaseItemLabelGenerator(generator);
        lineRenderer2.setBaseItemLabelGenerator(generator);
        double orient=(-Math.PI / 2.0);
        if(styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")){
          orient=0.0;
        }
        lineRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        lineRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        lineRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        lineRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

      }
    }

    // Bar Dataset Colors!
    if(colorMap!=null){
      int idx = -1;
      for (Iterator iterator = datasetBarFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
        idx++;
        String serName = (String) iterator.next();
        String labelName = "";
        int index=-1;

        if (seriesCaptions != null && seriesCaptions.size()>0){
          labelName = serName;
          serName = (String)seriesCaptions.get(serName);
          index=datasetBarFirstAxis.getRowIndex(labelName);
        }
        else
          index=datasetBarFirstAxis.getRowIndex(serName);

        Color color=(Color)colorMap.get(serName);
        if(color!=null){
          barRenderer1.setSeriesPaint(index, color);
       
      }

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

        if (seriesCaptions != null && seriesCaptions.size()>0){
          labelName = serName;
          serName = (String)seriesCaptions.get(serName);
          index=datasetBarSecondAxis.getRowIndex(labelName);
        }
        else
          index=datasetBarSecondAxis.getRowIndex(serName);

        Color color=(Color)colorMap.get(serName);
        if(color!=null){
          barRenderer2.setSeriesPaint(index, color);
       
      }       
    }




    // LINE Dataset Colors!
    if(useLinesRenderers==true){
      if(colorMap!=null){
        int idx = -1;
        for (Iterator iterator = datasetLineFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
          idx++;
          String serName = (String) iterator.next();
          String labelName = "";
          int index=-1;

          if (seriesCaptions != null && seriesCaptions.size()>0){
            labelName = serName;
            serName = (String)seriesCaptions.get(serName);
            index=datasetLineFirstAxis.getRowIndex(labelName);
          }
          else
            index=datasetLineFirstAxis.getRowIndex(serName);

          Color color=(Color)colorMap.get(serName);
          if(color!=null){
            lineRenderer1.setSeriesPaint(index, color);
         
        }

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

          if (seriesCaptions != null && seriesCaptions.size()>0){
            labelName = serName;
            serName = (String)seriesCaptions.get(serName);
            index=datasetLineSecondAxis.getRowIndex(labelName);
          }
          else
            index=datasetLineSecondAxis.getRowIndex(serName);

          Color color=(Color)colorMap.get(serName);
          if(color!=null){
            lineRenderer2.setSeriesPaint(index, color);
         
        }       
      }
    }


    //defines url for drill
    boolean document_composition=false;
    if(mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))document_composition=true;

    logger.debug("Calling Url Generation");


    MyCategoryUrlGenerator mycatUrl=null;
    if(super.rootUrl!=null){
      logger.debug("Set MycatUrl");
      mycatUrl=new MyCategoryUrlGenerator(super.rootUrl);

      mycatUrl.setDocument_composition(document_composition);
      mycatUrl.setCategoryUrlLabel(super.categoryUrlName);
      mycatUrl.setSerieUrlLabel(super.serieUrlname);
      mycatUrl.setDrillDocTitle(drillDocTitle);
      mycatUrl.setTarget(target);
    }
    if(mycatUrl!=null){
      barRenderer1.setItemURLGenerator(mycatUrl);
      barRenderer2.setItemURLGenerator(mycatUrl);
      if(useLinesRenderers){
        lineRenderer1.setItemURLGenerator(mycatUrl);
        lineRenderer2.setItemURLGenerator(mycatUrl);     
      }

    }


    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    JFreeChart 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.setBackgroundPaint(Color.white);

//    I want to re order the legend
    LegendItemCollection legends=plot.getLegendItems();
    // legend Temp
    HashMap<String, LegendItem> legendTemp=new HashMap<String, LegendItem>();
    Vector<String> alreadyInserted=new Vector<String>();
    for (int i = 0; i<legends.getItemCount(); i++) {
      LegendItem item=legends.get(i);
      String label=item.getLabel();
      legendTemp.put(label, item);
    }
    LegendItemCollection newLegend=new LegendItemCollection();
    // force the order of the ones specified
    for (Iterator iterator = seriesOrder.iterator(); iterator.hasNext();) {
      String serie = (String) iterator.next();
      if(legendTemp.keySet().contains(serie)){
        newLegend.add(legendTemp.get(serie));
        alreadyInserted.add(serie);
      }
    }
    // check that there are no serie not specified, otherwise add them
    for (Iterator iterator = legendTemp.keySet().iterator(); iterator.hasNext();) {
      String serie = (String) iterator.next();
      if(!alreadyInserted.contains(serie)){
        newLegend.add(legendTemp.get(serie));
      }
    }

    plot.setFixedLegendItems(newLegend);

    if(legend==true) drawLegend(chart);
    logger.debug("OUT");

    return chart;
View Full Code Here

       renderer2.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
       CategoryPlot subplot2 = new CategoryPlot(dataset, null, rangeAxis2, renderer2);
       subplot2.setDomainGridlinesVisible(true);

       CategoryAxis domainAxis = new CategoryAxis("Category");
       CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
       plot.add(subplot1, 2);
       plot.add(subplot2, 1);

       JFreeChart result = new JFreeChart(
           "Combined Domain Category Plot Demo",
           new Font("SansSerif", Font.BOLD, 12),
           plot,
View Full Code Here

                applyToCategoryItemRenderer(r);
            }
        }

        if (plot instanceof CombinedDomainCategoryPlot) {
            CombinedDomainCategoryPlot cp = (CombinedDomainCategoryPlot) plot;
            Iterator iterator = cp.getSubplots().iterator();
            while (iterator.hasNext()) {
                CategoryPlot subplot = (CategoryPlot) iterator.next();
                if (subplot != null) {
                    applyToPlot(subplot);
                }
            }
        }
        if (plot instanceof CombinedRangeCategoryPlot) {
            CombinedRangeCategoryPlot cp = (CombinedRangeCategoryPlot) plot;
            Iterator iterator = cp.getSubplots().iterator();
            while (iterator.hasNext()) {
                CategoryPlot subplot = (CategoryPlot) iterator.next();
                if (subplot != null) {
                    applyToPlot(subplot);
                }
View Full Code Here

        .setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot categoryplot1 = new CategoryPlot(categorydataset1, null,
        numberaxis1, barrenderer);
    categoryplot1.setDomainGridlinesVisible(true);
    CategoryAxis categoryaxis = new CategoryAxis("Category");
    CombinedDomainCategoryPlot combineddomaincategoryplot = new CombinedDomainCategoryPlot(
        categoryaxis);
    combineddomaincategoryplot.add(categoryplot, 2);
    combineddomaincategoryplot.add(categoryplot1, 1);
    JFreeChart jfreechart = new JFreeChart(
        "Combined Domain Category Plot Demo", new Font("SansSerif", 1,
            12), combineddomaincategoryplot, true);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
View Full Code Here

    /**
     * This is a test to replicate the bug report 987080.
     */
    public void testRemoveSubplot() {
        CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();
        CategoryPlot plot1 = new CategoryPlot();
        CategoryPlot plot2 = new CategoryPlot();
        plot.add(plot1);
        plot.add(plot2);
        // remove plot2, but plot1 is removed instead
        plot.remove(plot2);
        List plots = plot.getSubplots();
        assertTrue(plots.get(0) == plot1);
    }
View Full Code Here

    /**
     * Test the equals() method.
     */
    public void testEquals() {
       
        CombinedDomainCategoryPlot plot1 = createPlot();
        CombinedDomainCategoryPlot plot2 = createPlot();
        assertTrue(plot1.equals(plot2));   
       
    }
View Full Code Here

TOP

Related Classes of org.jfree.chart.plot.CombinedDomainCategoryPlot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.