ClusteredBar Combo Chart

Thiago Henrique Burgos <[email protected]> Wed, 20 Oct 2004 14:54:10 -0300
Newsgroups gmane.comp.krysalis.jcharts.user
Message-ID <[email protected]>
hello,

   is it possible to create a clustered bar with 2 bar instead of 3? 
beacuse I could´t make it out.
  When I put only two entries on my data variable it doenst work out.
Here is my class:

package org.jCharts.demo.simpleServlet;


import org.jCharts.axisChart.AxisChart;
import 
org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelPosition;
import 
org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelRenderer;
import org.jCharts.chartData.AxisChartDataSet;
import org.jCharts.chartData.DataSeries;
import org.jCharts.chartData.interfaces.IAxisDataSeries;
import org.jCharts.encoders.ServletEncoderHelper;
import org.jCharts.properties.*;
import org.jCharts.properties.util.ChartFont;
import org.jCharts.test.TestDataGenerator;
import org.jCharts.types.ChartType;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.awt.*;
import java.io.IOException;


public class ComboChartServlet extends HttpServlet
{
    //---all of my charts serviced by this Servlet will have the same 
properties.
    private LineChartProperties lineChartProperties;

    //---all of my charts serviced by this Servlet will have the same 
properties.
    private BarChartProperties barChartProperties;

    //---all of my charts serviced by this Servlet will have the same 
properties.
    protected LegendProperties legendProperties;
    protected AxisProperties axisProperties;
    protected ChartProperties chartProperties;

    protected int width = 550;
    protected int height = 360;


    
/**********************************************************************************************
     *
    
 **********************************************************************************************/
    public void init()
    {
        this.legendProperties = new LegendProperties();
        this.chartProperties = new ChartProperties();
        this.axisProperties = new AxisProperties( false );
        ChartFont axisScaleFont = new ChartFont( new Font( "Georgia 
Negreta cursiva", Font.PLAIN, 13 ), Color.black );
        axisProperties.getXAxisProperties().setScaleChartFont( 
axisScaleFont );
        axisProperties.getYAxisProperties().setScaleChartFont( 
axisScaleFont );

        ChartFont axisTitleFont = new ChartFont( new Font( "Arial 
Narrow", Font.PLAIN, 14 ), Color.black );
        axisProperties.getXAxisProperties().setTitleChartFont( 
axisTitleFont );
        axisProperties.getYAxisProperties().setTitleChartFont( 
axisTitleFont );

        ChartFont titleFont = new ChartFont( new Font( "Georgia Negreta 
cursiva", Font.PLAIN, 14 ), Color.black );
        this.chartProperties.setTitleFont( titleFont );


        Stroke[] strokes = {LineChartProperties.DEFAULT_LINE_STROKE};
        Shape[] shapes = {PointChartProperties.SHAPE_DIAMOND};
        this.lineChartProperties = new LineChartProperties( strokes, 
shapes );

        this.barChartProperties = new BarChartProperties();
    }


    
/**********************************************************************************************
     *
    
 **********************************************************************************************/
    public void service( HttpServletRequest req, HttpServletResponse 
httpServletResponse ) throws ServletException, IOException
    {
        try
        {
            String[] xAxisLabels = {"2002", "2003", "2004"};
            String xAxisTitle = "Meses";
            String yAxisTitle = "Numero de CRs";
            String title = "Backlog de CRs";
            IAxisDataSeries dataSeries = new DataSeries( xAxisLabels, 
xAxisTitle, yAxisTitle, title );
           
            ValueLabelRenderer valueLabelRenderer = new 
ValueLabelRenderer( false, false, true ,-1 );
            valueLabelRenderer.setValueLabelPosition( 
ValueLabelPosition.ON_TOP );           
            valueLabelRenderer.useVerticalLabels( false );
            barChartProperties.addPostRenderEventListener( 
valueLabelRenderer );
           
            //double[][] data= new double[][]{{ 145, 80, 55 }};
            double[][] dataLinha = new double[][]{{50, 50, 50}};
            //String[] legendLabels = {"Bugs"};
            String[] legendLine = {"backlog de CRs"};
            //Paint[] paints = new Paint[]{Color.gray.darker()};
            Paint[] linePaints = new Paint[]{Color.green};
           
                 double[][] data= new double[][]{
                         {120,80,55},
                         {25,10,84},
                         {45,18,5}              
                 };
                 String[] legendLabels= { "Bugs", "Security Holes", 
"Backdoors" };
                 Paint[] paints= TestDataGenerator.getRandomPaints( 3 );
                 ClusteredBarChartProperties 
clusteredBarChartProperties= new ClusteredBarChartProperties();
                 AxisChartDataSet axisChartDataSet= new 
AxisChartDataSet( data, legendLabels, paints, ChartType.BAR_CLUSTERED, 
clusteredBarChartProperties );
                 dataSeries.addIAxisPlotDataSet( axisChartDataSet );
   
                 ChartProperties chartProperties= new ChartProperties();
           
            //dataSeries.addIAxisPlotDataSet( new AxisChartDataSet( 
data, legendLabels, paints, ChartType.BAR, this.barChartProperties ) );
            dataSeries.addIAxisPlotDataSet( new AxisChartDataSet( 
dataLinha, legendLine, linePaints, ChartType.LINE, 
this.lineChartProperties ) );
               
            AxisChart axisChart = new AxisChart( dataSeries, 
this.chartProperties, this.axisProperties, this.legendProperties, 
this.width, this.height );
            ServletEncoderHelper.encodeJPEG13( axisChart, 1.0f, 
httpServletResponse );
        }
        catch( Throwable throwable )
        {
            //HACK do your error handling here...
            throwable.printStackTrace();
        }
    }
}

-- 
Thiago Henrique Burgos
Engenheiro de Configuração
______________________________________________________________
C.entro de E.studos e S.istemas A.vancados do R.ecife
Fone: +55 81 3425-4857
http://www.cesar.org.br 



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl