Peter Maloney - 2007-08-07

Logged In: YES
user_id=1621494
Originator: NO

I agree with Sirrug about the step requirement. This library is completely useless to me without specifying a step. I tried to make my own step by calculating my own greatest value and num labels count and the library fails to handle it properly. Even though I set the max value to 120, the max ends up being 200! The largest value in my data is 109, so it should not be overriding it. If I disable the custom values, it does the same except with non-stacked. It completely ignores my setting!! And the labels end up with a ridiculous unusable step {0,33,67,100,133,167,200}. I read that it should be overridden (which I disagree with) if the value I set is lower than the maximum value in the dataset, but this is not the case here. And it does not make sense for my setting to be automatically overridden, even if it seems invalid. If I set a value, obviously it is because I want to use that value, not because I wanted my setting to be ignored.

Here is a complete test with hardcoded greatest values. Test 1 is the most similar to what I am actually trying to do.

test 1,
stacked,
dataset max value is 109 (51+12+46),
customGreatestValue = 120,
axis shows {0,33,67,100,133,167,200}
FAILED! max should be 120, because 109 is lower.

test 2,
not stacked,
dataset max value is 51 (max of 51,12,46),
customGreatestValue = 120,
axis shows {0,33,67,100,133,167,200}
FAILED! max should be 120, because 51 is lower, not 200 which is nearly quadrouple the max value in the dataset and looks HORRIBLE.

test 3,
stacked,
dataset max value is 109 (51+12+46),
customGreatestValue = not set
axis shows {0,33,67,100,133,167,200}
FAILED! max should be around 110 or 120. 200 is almost double the max value and looks bad.

test 3,
stacked,
dataset max value is 109 (51+12+46),
customGreatestValue = not set
axis shows {0,10,20,30,40,50,60}
expected behavior, because 51 is the max value in the dataset. the step seems to be 10, which is nice, but I still had no control over it.

/*
* Main.java
*
* Created on August 2, 2007, 2:27 PM
*/

package experiments.guichart2;

import java.io.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;

import net.sourceforge.chart2d.*;

/**
*
* @author pmaloney
*/
public class BUG {

/** Creates a new instance of Main */
public BUG() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
File pwd = new File(".");
System.out.println( "pwd = " + pwd.getAbsolutePath() );
File tmp = new File("tmp");
tmp.mkdir();

test("tmp/test1.png", true, 120);
test("tmp/test2.png", false, 120);
test("tmp/test3.png", true, -1);
test("tmp/test4.png", false, -1);
}

public static void test(String filename, boolean stacked, float customGreatestValue) {
String title = "Sales 2006";
String marginLabelBottom = "Month Ending";
String marginLabelLeft = "Units (k)";
String[] legendLabels = new String[]{"On order", "Reserved", "Completed", };
String[] labels = new String[]{"May-07"};
int numbersAxisNumLabels = 7;

Object2DProperties o2p = new Object2DProperties();
o2p.setObjectBorderColor(java.awt.Color.DARK_GRAY);
//o2p.setObjectTitleFontColor(java.awt.Color);
o2p.setObjectTitleText( title );

Chart2DProperties c2p = new Chart2DProperties();
//c2p.setChartDataLabelsPrecision(2);

GraphChart2DProperties gc2p = new GraphChart2DProperties();
gc2p.setLabelsAxisLabelsTexts( labels );
gc2p.setNumbersAxisTitleText( marginLabelLeft );
gc2p.setLabelsAxisTitleText( marginLabelBottom );

gc2p.setChartDatasetCustomizeLeastValue( true );
gc2p.setChartDatasetCustomLeastValue( 0 );
if( customGreatestValue != -1 ) {
gc2p.setChartDatasetCustomGreatestValue( customGreatestValue );
gc2p.setChartDatasetCustomizeGreatestValue( true );
}
gc2p.setNumbersAxisNumLabels( numbersAxisNumLabels ); //includes 0
gc2p.setChartGraphableToAvailableRatio( 1f );

LegendProperties lp = new LegendProperties();
lp.setLegendExistence( true );
lp.setLegendLabelsTexts( legendLabels );

Dataset dataSet = new Dataset(3, 1, 1);

dataSet.add(0, 0, 0, 51f);
dataSet.add(1, 0, 0, 12f);
dataSet.add(2, 0, 0, 46f);

if( stacked ) {
dataSet.doConvertToStacked();
}

MultiColorsProperties mcp = new MultiColorsProperties();
mcp.setColorsType( MultiColorsProperties.PASTEL );
mcp.setColorsCustomize( false );

GraphProperties graphProps = new GraphProperties();
graphProps.setGraphAllowComponentAlignment (true);
graphProps.setGraphBarsRoundingRatio (0f);
graphProps.setGraphOutlineComponentsExistence (true);

LBChart2D chart = new LBChart2D();
chart.setObject2DProperties( o2p );
chart.setChart2DProperties( c2p );
chart.setGraphChart2DProperties( gc2p );
chart.setLegendProperties( lp );
chart.addGraphProperties( graphProps );
chart.addMultiColorsProperties( mcp );
chart.addDataset( dataSet );

//Optional validation: Prints debug messages if invalid only.
if( !chart.validate( false ) )
chart.validate( true );

BufferedImage image = chart.getImage();
try{
ImageIO.write( image, "png", new File(filename) );
}catch(IOException e) {
e.printStackTrace();
}

System.out.println("Done! filename = " + filename);
}

}