ChartDirector 5.1 (PHP Edition)

Shape Specification


Several ChartDirector API accept shape specification as arguments. For example, BarLayer.setBarShape and BarLayer.setBarShape2 can be used to specify shapes of bars in bar charts, while DataSet.setDataSymbol, DataSet.setDataSymbol4, PolarLayer.setDataSymbol and PolarLayer.setDataSymbol4 can be used to specify shapes for data symbols.

Note that in addition to shapes, in many cases ChartDirector also accepts images or custom draw objects for data representation. For example, see DataSet.setDataSymbol2, DataSet.setDataSymbol3, PolarLayer.setDataSymbol2 and PolarLayer.setDataSymbol3.

Built-In Shapes

Built-in shapes are specified as integers. The integers can be explicit constants, or can be generated by a ChartDirector method for parameterized shapes. For example, a circle is represented by an explicit constant CircleShape (=7). On the other hand, the number representing a polygon depends on the number of sides the polygon has, so it is generated by using the PolygonShape method, passing in the number of sides as argument.

The following table illustrates the various ChartDirector shapes:



Shape IdValueDescription
SquareShape1Square shape. See (5, 1) above.
DiamondShape2Diamond shape. See (6, 1) above.
TriangleShape3Triangle shape pointing upwards. See (1, 2) above.
RightTriangleShape4Triangle shape pointing rightwards. See (2, 2) above.
LeftTriangleShape5Triangle shape pointing leftwards. See (3, 2) above.
InvertedTriangleShape6Triangle shape pointing downwards. See (4, 2) above.
CircleShape7Circle shape. See (1, 1) above.
GlassSphereShape15Glass sphere shape. See (2, 1) above.
GlassSphere2Shape16Bright glass sphere shape. See (3, 1) above.
SolidSphereShape17Solid sphere shape. See (4, 1) above.
StarShape[Method]Star shapes of various points. See (5, 2), (6, 2), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (6, 3) above for stars with 3 to 10 points.
PolygonShape[Method]Polygon shapes symmetrical about a vertical axis with a vertex at the top center position. See (1, 4) and (3, 4) for polygons of 5 and 6 sides.
Polygon2Shape[Method]Polygon shapes symmetrical about a vertical axis but without any vertex at the top center position. See (2, 4), (4, 4) for polygons of 5 and 6 sides.
CrossShape[Method]'+' shapes. See (5, 4), (6, 4), (1, 5), (2, 5), (3, 5), (4, 5), (5, 5) for '+' shape with arm width of 0.1 - 0.7.
Cross2Shape[Method]'X' shapes. See (6, 5), (1, 6), (2, 6), (3, 6), (4, 6), (5, 6), (6, 6) for 'X' shapes with arm width of 0.1 - 0.7.

Custom Shapes

In ChartDirector, custom shapes are specified as an array of integers x0, y0, x1, y1, x2, y2 ... representing the coordinates of the vertices of the custom polygonal shape.

The polygon should be defined with a bounding square of 1000 x 1000 units, in which the x-axis is from -500 to 500 going from left to right, and the y-axis is from 0 to 1000 going from bottom to top.

ChartDirector will automatically scale the polygon so that 1000 units will become to the pixel size as requested by the various ChartDirector API.

As an example, the shape of the standard diamond shape in ChartDirector is represented as an array with 8 numbers:

0, 0, 500, 500, 0, 1000, -500, 500