Easily implement data pie chart in the JSP page

xiaoxiao2021-03-06  41

Making the adjustable boundary map A of the cakes in the border, how can I change the size of the boundary? Int border = 10 can be defined first, and then calculate the size of the area in the boundary:

Ellipse2d.double ELB = New Ellipse2d.double (x_pie - border / 2, y_pie - border / 2, piewidth border, pieheight border);

The value of x_pie and y_pie represents the upper left corner of the square surrounded by a square graphic. We take half of the border / 2 to get the center of the cake graphic through the boundary area.

Arc (ARC) theory

The Fillarc () method inherited from the Java.awt.Graphics class provides a simple way to draw each part (or arc) of the cake graphics:

G2d.fillarc (x_position, y_position, width, height, startangle, swherepangle);

X_Position, and Y_Position integers represent the X, Y coordinates of the upper left corners of the arc to be filled, and Width and Heigh integers represent their specific size. If Width and Height are equal, the cake graphic will be a circle. If width and height are not equal, the piematic graphic will be an ellipse.

The Fillarc () method determines the size of the arc based on the Sweepangle integer value. If the SWEEPANGLE value is positive, the arc is drawn in the reverse clockwise direction, so that it is clockwise.

Plot arc

The first step is to get the color of the nearest cake arc using the getpiecolor () method of the PIECOLOR object and gives it the current arc ::

g2d.setcolor (pc.getpiecolor ());

Next, a total sales amount is obtained by constantly cycling Sales [] arrays and makes it accumulates:

Salestotal = Sales [i];

With a total sales volume, you can calculate the percentage of each product sales in total sales.

Float perc = (Sales [i] / salestotal);

We calculate Sweepangle to assign each part of the arc:

INT SWEEPANGLE = (int) (Perc * 360);

After each part of the arc painted, Startangle can be incremented according to the current Sweepangle. This ensures that the current circular arc portion is the above arc as the beginning, thereby establishing a complete cake pattern.

Display icon

The icon provides the simplest way of displaying the individual parts of the cake. The size of an icon should correspond to the occupancy of the pie in the cake.

Figure B shows a complete cake pattern and its icon corresponding to each part, including product name, sales of sales, and various parts.

Figure B

to sum up

This paper tells how to use JSP to draw a method and algorithm for drawing a pie graphic, these methods and algorithms are simple and practical, and developers can fully utilize these methods.

转载请注明原文地址:https://www.9cbs.com/read-86178.html

New Post(0)