3D Category Chart
General info on how to use the 3D Charting API can be found under '3D numerical chart'.
The data
A categorical representation is only possible for grid-based data. In terms of the API this means any class deriving WAbstractGridData . JWt already provides two implementations: WGridData and WEquidistantGridData . To create a categorical chart, the chart must be configured as such (by setting the type to CategoryChart) and the data which is added to this chart must be of the type BarSeries3D.
A categorical chart also allows multiple data series to be shown if the dimensions are the same. The different bar-series are then stacked on top of each other.
source
void CatChart3d () {
WContainerWidget container = new WContainerWidget ();
final WCartesian3DChart chart = new WCartesian3DChart (( WContainerWidget ) container );
chart . setType ( ChartType . Category );
chart . setRenderOptions ( EnumSet . of ( GLRenderOption . ClientSide , GLRenderOption . AntiAliasing ));
final WCssDecorationStyle style = new WCssDecorationStyle ();
style . setBorder (
new WBorder ( BorderStyle . Solid , BorderWidth . Medium , new WColor ( StandardColor . Black )));
chart . setDecorationStyle ( style );
chart . resize ( new WLength ( 800 ), new WLength ( 600 ));
chart . setTitle ( "Fish consumption in western Europe" );
chart . axis ( Axis . Z3D ). setTitle ( "Consumption (pcs/year)" );
chart . setLegendStyle ( new WFont (), new WPen (), new WBrush ( new WColor ( StandardColor . LightGray )));
chart . setLegendEnabled ( true );
chart . setGridEnabled ( Plane . XZ , Axis . Z3D , true );
chart . setGridEnabled ( Plane . YZ , Axis . Z3D , true );
WStandardItemModel model = CsvUtil . csvToModel ( "" + "fish_consumption.csv" , false );
for ( int i = 0 ; i < model . getRowCount (); i ++ ) {
for ( int j = 0 ; j < model . getColumnCount (); j ++ ) {
if (( StringUtils . asString ( model . getData ( 0 , j ))
. toString ()
. equals ( new WString ( "codfish" ). toString ()))
&& ( StringUtils . asString ( model . getData ( i , 0 ))
. toString ()
. equals ( new WString ( "Belgium" ). toString ()))) {
model . setData ( i , j , new WColor ( StandardColor . Cyan ), ItemDataRole . MarkerBrushColor );
}
}
}
WGridData isotopes = new WGridData ( model );
isotopes . setTitle ( "made-up data" );
isotopes . setType ( Series3DType . Bar );
chart . addDataSeries ( isotopes );
chart . setBackground ( new WColor ( StandardColor . Transparent ));
if ( WApplication . getInstance (). getTheme (). getColorMode (). equals ( "dark" )) {
chart . setIntersectionLinesColor ( new WColor ( StandardColor . White ));
chart . setGridLinesPen ( new WPen ( StandardColor . White ));
chart . setCubeLinesPen ( new WPen ( StandardColor . White ));
chart . setTitleColor ( new WColor ( StandardColor . White ));
chart . axis ( Axis . X3D ). setPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . X3D ). setTextPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Y3D ). setPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Y3D ). setTextPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Z3D ). setPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Z3D ). setTextPen ( new WPen ( StandardColor . White ));
chart . setAlternativeContent (
new WImage ( new WLink ( "pics/categoricalChartScreenshot-dark.png" )));
} else {
chart . setAlternativeContent ( new WImage ( new WLink ( "pics/categoricalChartScreenshot.png" )));
}
WApplication . getInstance ()
. themeColorModeChanged ()
. addListener (
this ,
( String mode ) -> {
if ( mode . equals ( "dark" )) {
chart . setIntersectionLinesColor ( new WColor ( StandardColor . White ));
chart . setGridLinesPen ( new WPen ( StandardColor . White ));
chart . setCubeLinesPen ( new WPen ( StandardColor . White ));
chart . setTitleColor ( new WColor ( StandardColor . White ));
chart . axis ( Axis . X3D ). setPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . X3D ). setTextPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Y3D ). setPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Y3D ). setTextPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Z3D ). setPen ( new WPen ( StandardColor . White ));
chart . axis ( Axis . Z3D ). setTextPen ( new WPen ( StandardColor . White ));
chart . setAlternativeContent (
new WImage ( new WLink ( "pics/categoricalChartScreenshot-dark.png" )));
} else {
chart . setIntersectionLinesColor ( new WColor ( StandardColor . Black ));
chart . setGridLinesPen ( new WPen ( StandardColor . Black ));
chart . setCubeLinesPen ( new WPen ( StandardColor . Black ));
chart . setTitleColor ( new WColor ( StandardColor . Black ));
chart . axis ( Axis . X3D ). setPen ( new WPen ( StandardColor . Black ));
chart . axis ( Axis . X3D ). setTextPen ( new WPen ( StandardColor . Black ));
chart . axis ( Axis . Y3D ). setPen ( new WPen ( StandardColor . Black ));
chart . axis ( Axis . Y3D ). setTextPen ( new WPen ( StandardColor . Black ));
chart . axis ( Axis . Z3D ). setPen ( new WPen ( StandardColor . Black ));
chart . axis ( Axis . Z3D ). setTextPen ( new WPen ( StandardColor . Black ));
chart . setAlternativeContent (
new WImage ( new WLink ( "pics/categoricalChartScreenshot.png" )));
}
});
}