/**
* 区域图表
*
* @author Administrator
*
*/
public class AreaChart extends JComponent {
public AreaChart() {
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int width = this.getWidth();
int height = this.getHeight();
g2d.setColor(this.background);
g2d.fillRect(0, 0, width, height);
double gridCellWidth = width * this.gridCellPercent;
double gridCellHeight = height * this.gridCellPercent;
g2d.setColor(this.gridColor);
g2d.setStroke(this.gridStroke);
for (int x = 0; x < width; x += gridCellWidth) {
g2d.drawLine(x, 0, x, height);
}
for (int y = 0; y < height; y += gridCellHeight) {
g2d.drawLine(0, y, width, y);
}
double x = 0;
double y = height;
final double delta = this.maxValue - this.minValue;
GeneralPath path = new GeneralPath();
path.moveTo(x, y);
for (int index = 0; index < this.values.size(); index++) {
double value = this.values.get(index);
x += gridCellWidth;
y = height - (value - this.minValue) / delta * height;
path.lineTo(x, y);
}
path.lineTo(width, height);
path.closePath();
g2d.setColor(this.areaColor);
g2d.fill(path);
}
public void setBackground(Color background) {
this.background = background;
}
public void addValue(double value) {
if (this.values.size() >= maxCount) {
this.values.remove(0);
}
if (this.maxValue < value) {
this.maxValue = value;
}
if (this.minValue > value) {
this.minValue = value;
}
this.values.add(value);
}
public void setVal