Hello, I have a problem in set max value for horizontal axis.
I’m still trying to construct 4-field graph, so
There is a code
public class FourFieldChart
{
static Workbook workbook;
static int minX, maxX, minY, maxY, crossX, crossY;
public static final void main( String[] args )
{
try
{
NewBasisTool.setDatabaseServer( DataBaseConstants.TEST_APP );
NewBasisTool.setUpHibernate( DataBaseConstants.TEST_APP );
}
catch( TConnectionNotAvailableException e )
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
print4FieldGraph();
}
private static void print4FieldGraph()
{
workbook = new Workbook();
minX = 0; maxX = 20;
minY = 0; maxY = 20;
crossX = 10; crossY = 10;
setValues();
Worksheet worksheet = workbook.getWorksheets().get( 0 );
int index = worksheet.getCharts().add( ChartType.SCATTER, 10, 0, 25, 8 );
Chart chart = worksheet.getCharts().get( index );
//chart.getSecondValueAxis().setVisible( true );
//chart.getSecondCategoryAxis().setVisible( true );
//set Quarters
setQuarters();
//chart.setAutoScaling( false );
chart.getNSeries().setCategoryData( “=B3:B11” );
int baseIndex = chart.getNSeries().add( “C19:C25”, true );
chart.getNSeries().get( baseIndex ).setXValues( “=B19:B25” );
chart.getNSeries().get( baseIndex ).setName( “BaseLine” );
chart.getNSeries().get( baseIndex ).setType( ChartType.AREA_STACKED );
int bLeftIndex = chart.getNSeries().add( “D19:D25”, true );
chart.getNSeries().get( bLeftIndex ).setXValues( “=B19:B25” );
chart.getNSeries().get( bLeftIndex ).setName( “BotLeft” );
chart.getNSeries().get( bLeftIndex ).setType( ChartType.AREA_STACKED );
int bRightIndex = chart.getNSeries().add( “E19:E25”, true );
chart.getNSeries().get( bRightIndex ).setXValues( “=B19:B25” );
chart.getNSeries().get( bRightIndex ).setName( “BotRight” );
chart.getNSeries().get( bRightIndex ).setType( ChartType.AREA_STACKED );
int topLeftIndex = chart.getNSeries().add( “F19:F25”, true );
chart.getNSeries().get( topLeftIndex ).setXValues( “=B19:B25” );
chart.getNSeries().get( topLeftIndex ).setName( “TopLeft” );
chart.getNSeries().get( topLeftIndex ).setType( ChartType.AREA_STACKED );
int topRightIndex = chart.getNSeries().add( “G19:G25”, true );
chart.getNSeries().get( topRightIndex ).setXValues( “=B19:B25” );
chart.getNSeries().get( topRightIndex ).setName( “TopRight” );
chart.getNSeries().get( topRightIndex ).setType( ChartType.AREA_STACKED );
//set Values
int valueIndex = chart.getNSeries().add( “C3:C11”, true );
chart.getNSeries().get( valueIndex ).setXValues( “=B3:B11” );
chart.getNSeries().get( valueIndex ).setName( “Values” );
chart.getNSeries().get( valueIndex ).setType( ChartType.SCATTER );
//add labels
chart.getValueAxis().getTitle().setText( “X Axis” );
chart.getCategoryAxis().getTitle().setText( “Y Axis” );
// for beauty chart
chart.getNSeries().get( valueIndex ).setPlotOnSecondAxis( true );
chart.getSecondValueAxis().setVisible( true );
chart.getSecondCategoryAxis().setVisible( true );
chart.getValueAxis().setCrossType( CrossType.MAXIMUM );
chart.getValueAxis().setMaxValue( 20 );
chart.getValueAxis().setMinValue( 0 );
chart.getSecondCategoryAxis().setMaxValue( 20 );
chart.getSecondValueAxis().setCrossType( CrossType.AUTOMATIC );
//aChart.getSecondCategoryAxis().setTickLabelPosition( TickLabelPositionType.NONE );
chart.getSecondValueAxis().setVisible( false );
chart.getCategoryAxis().setCategoryType( CategoryType.TIME_SCALE );
chart.getCategoryAxis().setAutomaticMajorUnit( true );
chart.getCategoryAxis().setTickLabelPosition( TickLabelPositionType.NONE );
chart.getCategoryAxis().setMajorTickMark( TickMarkType.NONE );
try
{
workbook.save( “some_path\book1.xlsx” );
workbook.save( "
some_path\book1.xls" );
}
catch( Exception e )
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
private static void setQuarters()
{
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get( 0 );
Cells cells = sheet.getCells();
cells.get( “B19” ).setValue( 0 );
cells.get( “B20” ).setValue( 0 );
cells.get( “B21” ).setValue( 500 );
cells.get( “B22” ).setValue( 500 );
cells.get( “B23” ).setValue( 500 );
cells.get( “B24” ).setValue( 1000 );
cells.get( “B25” ).setValue( 1000 );
cells.get( “C19” ).setValue( 0 );
cells.get( “C20” ).setValue( 0 );
cells.get( “C21” ).setValue( 0 );
cells.get( “C22” ).setValue( 0 );
cells.get( “C23” ).setValue( 0 );
cells.get( “C24” ).setValue( 0 );
cells.get( “C25” ).setValue( 0 );
cells.get( “D19” ).setValue( 0 );
cells.get( “D20” ).setValue( 10 );
cells.get( “D21” ).setValue( 10 );
cells.get( “D22” ).setValue( 0 );
cells.get( “D23” ).setValue( 0 );
cells.get( “D24” ).setValue( 0 );
cells.get( “D25” ).setValue( 0 );
cells.get( “D26” ).setValue( 0 );
cells.get( “E19” ).setValue( 0 );
cells.get( “E20” ).setValue( 0 );
cells.get( “E21” ).setValue( 0 );
cells.get( “E22” ).setValue( 0 );
cells.get( “E23” ).setValue( 10 );
cells.get( “E24” ).setValue( 10 );
cells.get( “E25” ).setValue( 0 );
cells.get( “F19” ).setValue( 0 );
cells.get( “F20” ).setValue( 10 );
cells.get( “F21” ).setValue( 10 );
cells.get( “F22” ).setValue( 0 );
cells.get( “F23” ).setValue( 0 );
cells.get( “F24” ).setValue( 0 );
cells.get( “F25” ).setValue( 0 );
cells.get( “F26” ).setValue( 0 );
cells.get( “G19” ).setValue( 0 );
cells.get( “G20” ).setValue( 0 );
cells.get( “G21” ).setValue( 0 );
cells.get( “G22” ).setValue( 0 );
cells.get( “G23” ).setValue( 10 );
cells.get( “G24” ).setValue( 10 );
cells.get( “G25” ).setValue( 0 );
}
private static void setValues()
{
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get( 0 );
Cells cells = sheet.getCells();
cells.get( “B3” ).setValue( 9.22 );
cells.get( “B4” ).setValue( 15.46 );
cells.get( “B5” ).setValue( 13.57 );
cells.get( “B6” ).setValue( 8.5 );
cells.get( “B7” ).setValue( 9.19 );
cells.get( “B8” ).setValue( 6.24 );
cells.get( “B9” ).setValue( 18.24 );
cells.get( “B10” ).setValue( 19.62 );
cells.get( “B11” ).setValue( 19.6 );
cells.get( “C3” ).setValue( 11.57 );
cells.get( “C4” ).setValue( 16.69 );
cells.get( “C5” ).setValue( 14.09 );
cells.get( “C6” ).setValue( 16.84 );
cells.get( “C7” ).setValue( 6.19 );
cells.get( “C8” ).setValue( 9.06 );
cells.get( “C9” ).setValue( 2.68 );
cells.get( “C10” ).setValue( 3.16 );
cells.get( “C11” ).setValue( 3.33 );
}
}
In attachment you can see result excel files.
So I have a question, notice, I'm set max value to 20
chart.getSecondCategoryAxis().setMaxValue( 20 );
But in result in excel 2003 (xls) max value is 25 (automatic setted). And cause this, value dots on graph are replaced.
You can notice this if you compare xls and xlsx files.
So, how can I set max value for secondCategoryAxis in my case?
Also I insert screen for you, to better understand.
Thanks.