private static final String[] MONTH_NAMES = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };
public Widget createExample()
{
PlotModel model = new PlotModel();
PlotOptions plotOptions = new PlotOptions();
BarSeriesOptions barSeriesOptions = new BarSeriesOptions();
barSeriesOptions.setShow( true );
barSeriesOptions.setLineWidth( 1 );
barSeriesOptions.setBarWidth( 1 );
barSeriesOptions.setAlignment( BarAlignment.CENTER );
plotOptions.setGlobalSeriesOptions( new GlobalSeriesOptions().setBarsSeriesOptions( barSeriesOptions ) );
plotOptions.setLegendOptions( new LegendOptions().setShow( false ) );
// add tick formatter to the options
plotOptions.setXAxisOptions( new AxisOptions().setTicks( 12 ).setTickFormatter( new TickFormatter()
{
public String formatTickValue( double tickValue, Axis axis )
{
if ( tickValue > 0 && tickValue <= 12 )
{
return MONTH_NAMES[(int) ( tickValue - 1 )];
}
return "";
}
} ) );
// create a series
SeriesHandler handler = model.addSeries( "Ottawa's Month Temperatures (Daily Average in °C)", "blue" );
// add data
handler.add( new DataPoint( 1, -10.5 ) );
handler.add( new DataPoint( 2, -8.6 ) );
handler.add( new DataPoint( 3, -2.4 ) );