4.1.2 Bar Series

This series draws various types of bars. It uses ChartDataModel as its data model. Bars are of equal widths. Width is chosen in such a way, that bars never overlap, but are as thick as possible. KEYS specify bar positions on the horizontal axis. VALUES specify bar top value. There are several types of BarSeries. It is possible to use enumeration BarStrategies to choose the appropriate bar drawing strategy. However, if there is a requirement for a custom type of strategy, it is possible to set it directly to the style sheet, using tag “strategy”, e.g. style.setObject(“strategy”, new MyStrategy()).

Setting BarSeries object:

1
2
3
4
//Setting BarSeries object named bar1 where:
// chartDataModel  is an instance of ChartDataModel and holds values that will be mapped
// xMapper and yMapper are instances of AxisMapper and will represent values on axis
BarSeries bar1 = new BarSeries(chartDataModel, xMapper, yMapper);

Bar Series

Bar Series, is a chart with rectangular bars. Lengths of those bars are proportional to values, which they represent. Length is determined by VALUE and position where bar should stand - by KEY. This series can be horizontally or vertically oriented. Setting bar strategy for object bars1, which is an instance of BarSeries:

 
bars1.setStrategy(BarStrategies.BAR_STRATEGY);

Bar Series Demonstration

Figure 4.1.2.1 Bar Series Demonstration

View Source

Error Series

Error Series is a chart, where bars are represented by straight lines, where KEYS specify bar positions on the horizontal axis. And bar length is specified by VALUE and EXTENT. VALUE is the point where bar should start and EXTENT shows of how much bar length should be painted up and down counting from VALUE to EXTENT.

Setting error bar strategy for object bars2, which is an instance of BarSeries:

 
errorBar.setStrategy(BarStrategies.ERROR_BAR_STRATEGY);

Error Series Demonstration

Figure 4.1.2.2 Error Bar Series Demonstration

View Source

Event Series

Event chart uses ChartDataModel as its data model. This series takes points, where one is the starting point, which is described by KEY and VALUE, and another point is the ending point, which is also described by EXTENT and VALUE. These points are mapped and plotted. And then these points are connected with straight-line segments.

Setting event strategy for object bars3, which is an instance of BarSeries:

 
bars3.setStrategy(BarStrategies.EVENT_STRATEGY);

Event Series Demonstration

Figure 4.1.2.3 Event Series Demonstration

View Source

Floating Bar Series

Floating Bar Series use ChartDataModel as its data model. KEYS specify bar positions on the horizontal axis. EXTENT specify height of each bar. Finally, VALUE specify the bottom line of each bar. Height is counted starting from the bottom line of a bar specified by VALUE to EXTENT. Bars are of equal widths. Width is chosen in such a way, that bars never overlap, but are as thick as possible.

Setting floating bar strategy for object bars4, which is an instance of BarSeries:

 
bars4.setStrategy(BarStrategies.FLOATING_BAR_STRATEGY);

Floating Bar Series Demonstration

Figure 4.1.2.4 Floating Bar Series Demonstration

View Source

Waterfall Series

Waterfall Series is similar to FloatingBarSeries, however it shows how total value has increased by a series of intermediate values, then leading to final value which is a sum of intermediate values.

Setting waterfall bar strategy for object bars5, which is an instance of BarSeries:

 
bars5.setStrategy(BarStrategies.WATERFALL_STRATEGY );

Setting sum of intermediate values:

1
2
3
4
//sets bar to be visible which will represent a sum of intermediate values
((WaterfallBarStrategy)bar1.getStrategy()).setCumulativeValueVisible(true);
//sets title for bar which will represent a sum of intermediate values
((WaterfallBarStrategy)bar1.getStrategy()).setCumulativeValueTitle("Sum");

Waterfall Bar Series Demonstration

Figure 4.1.2.5 Waterfall Bar Series Demonstration

View Source

100% Stacked Bar Series

This series displays data as stacked bars and total proportion of each bar is always 100%.

Setting 100% Stacked Bar bar strategy for object bars1, bars2 and bars3, which are instances of BarSeries:

 
bars1.setStrategy(BarStrategies.PERCENTAGE_AREA_BAR_STRATEGY);
bars2.setStrategy(BarStrategies.PERCENTAGE_AREA_BAR_STRATEGY);
bars3.setStrategy(BarStrategies.PERCENTAGE_AREA_BAR_STRATEGY);

100% Stacked Bar Series Demonstration

Figure 4.1.2.6 100% Stacked Bar Series Demonstration

View Source

Other Bar Series Properties

Shapes

There are several types of shapes of bars.

Possible Shapes are:

Setting shapes for different BarSeries objects:

 
bar1.setPrimitive(Shapes.ERROR_BAR_SHAPE);
bar2.setPrimitive(Shapes.LINE_BAR_SHAPE);
bar3.setPrimitive(Shapes.PYRAMID_SHAPE);

Bar Shape Line Demonstration

Figure 4.1.2.7 Bar Shape Line Demonstration

Bar Shape Pyramid Demonstration

Figure 4.1.2.8 Bar Shape Pyramid Demonstration

Also it is possible to set a custom shape to the style sheet the same way as bar strategy:

 
style.setObject("primitive",new CustomShape());
Bar Spacing

It is possible to set spacing between bars for all series in a chart. In order to achieve this, static method setBarSpacing() should be used. The first parameter indicates for which axis it will be set, second parameter sets space between bars, which is relative to bar width. Values between 0 and 1 should be used. Also, setting values between [-1;0] permits overlapping of bars.

Setting bar spacing to 0.5f:

 
BarSeries.setBarSpacing(xMapper, 0.5f);

0.5f spacing among bars

Figure 4.1.2.8 0.5f spacing among bars

For source of this chart, please refer to section “Bar Series”.

Setting bar spacing to 0f:

 
BarSeries.setBarSpacing(xMapper, 0f);

0f spacing among bars

Figure 4.1.2.9 0f spacing among bars

For source of this chart, please refer to section “Bar Series”.

Series Spacing

There is a possibility to set spacing between series. With the intention to do this, static method setSeriesSpacing() should be used. The first parameter indicates for which axis it will be set, second parameter sets space between bars, which is relative to bar width. Values between 0 and 1 should be used. Also, setting values between [-1;0] permits overlapping of series.

Setting series spacing to 0.1f:

 
BarSeries.setSeriesSpacing(xMapper, 0.1f);

0.1f spacing between series

Figure 4.1.2.10 0.1f spacing between series

For source of this chart, please refer to section “Bar Series”.

Setting series spacing to 0.6f:

 
BarSeries.setSeriesSpacing(yMapper, 0.6f);

0.6f spacing between series

Figure 4.1.2.11 0.6f spacing between series

For source of this chart, please refer to section “Bar Series”.