📄 sdachart.java
字号:
if (series.isShowMarks()) { if (type == SDAChartSeries.svNone) { value = ""; } if (type == SDAChartSeries.svValue) { value = String.valueOf(pd.yValue); } if (type == SDAChartSeries.svXValue) { value = String.valueOf(pd.xValue); } if (type == SDAChartSeries.svPercent) { value = pd.percent; } if (type == SDAChartSeries.svXYValue) { value = pd.xValue + "/" + pd.yValue; } if (type == SDAChartSeries.svXValuePercent) { value = pd.xValue + "/" + pd.percent; } if (type == SDAChartSeries.svLabel) { value = pd.label; } if (type == SDAChartSeries.svLabelValue) { value = pd.label + "/" + pd.yValue; } if (type == SDAChartSeries.svLabelPercent) { value = pd.label + "/" + pd.percent; } if (value.length() > 0) { g.setColor(foreColor); drawLine(g, x1, y1, x1, y1 - 6); g.setColor(mack); fillRect(g, x1 - (ft.stringWidth(value)) / 2 + 1, y1 - 6 - fontHeight, ft.stringWidth(value) + 3, fontHeight); g.setColor(foreColor); drawRect(g, x1 - (ft.stringWidth(value)) / 2 + 1, y1 - 6 - fontHeight, ft.stringWidth(value) + 3, fontHeight); drawString(g, value, x1 - (ft.stringWidth(value)) / 2 + 3, y1 - 6 - fontHeight); } } } } //柱图 private void paintBarSeries(Graphics g, SDAChartSeries series) { SDAChartSeries.PointData pd = null; Font ft = getFont(); int fontHeight = ft.getHeight(); int x1 = 0, y1 = 0, y2 = getYPos(0); int mack = series.getMarksBackColor(); byte type = series.getMarkValueType(); String value = ""; series.calPercent(); SetClip(g, xStartPos + 1, yStartPos - yLen + 1, xLen - 1, yLen - 1); for (int i = 0; i < series.getDataCount(); i++) { pd = series.getData(i); x1 = getXPos(pd.xValue); y1 = getYPos(pd.yValue); //柱 if (y1 > y2) { g.setColor(pd.color); fillRect(g, x1 - barChartWidth / 2, y2, barChartWidth, y1 - y2); g.setColor(foreColor); drawRect(g, x1 - barChartWidth / 2, y2, barChartWidth, y1 - y2); } else { g.setColor(pd.color); fillRect(g, x1 - barChartWidth / 2, y1, barChartWidth, y2 - y1); g.setColor(foreColor); drawRect(g, x1 - barChartWidth / 2, y1, barChartWidth, y2 - y1); } //画标识 if (series.isShowMarks()) { if (type == SDAChartSeries.svNone) { value = ""; } if (type == SDAChartSeries.svValue) { value = String.valueOf(pd.yValue); } if (type == SDAChartSeries.svXValue) { value = String.valueOf(pd.xValue); } if (type == SDAChartSeries.svPercent) { value = pd.percent; } if (type == SDAChartSeries.svXYValue) { value = pd.xValue + "/" + pd.yValue; } if (type == SDAChartSeries.svXValuePercent) { value = pd.xValue + "/" + pd.percent; } if (type == SDAChartSeries.svLabel) { value = pd.label; } if (type == SDAChartSeries.svLabelValue) { value = pd.label + "/" + pd.yValue; } if (type == SDAChartSeries.svLabelPercent) { value = pd.label + "/" + pd.percent; } if (value.length() > 0) { if (y1 < y2) { g.setColor(foreColor); drawLine(g, x1, y1, x1, y1 - 6); g.setColor(mack); fillRect(g, x1 - (ft.stringWidth(value)) / 2 + 1, y1 - 6 - fontHeight, ft.stringWidth(value) + 3, fontHeight); g.setColor(foreColor); drawRect(g, x1 - (ft.stringWidth(value)) / 2 + 1, y1 - 6 - fontHeight, ft.stringWidth(value) + 3, fontHeight); drawString(g, value, x1 - (ft.stringWidth(value)) / 2 + 3, y1 - 6 - fontHeight); } else { g.setColor(foreColor); drawLine(g, x1, y1, x1, y1 + 6); g.setColor(mack); fillRect(g, x1 - (ft.stringWidth(value)) / 2 + 1, y1 + 6, ft.stringWidth(value) + 3, fontHeight); g.setColor(foreColor); drawRect(g, x1 - (ft.stringWidth(value)) / 2 + 1, y1 + 6, ft.stringWidth(value) + 3, fontHeight); drawString(g, value, x1 - (ft.stringWidth(value)) / 2 + 3, y1 + 6); } } } } } //饼图 private void paintPieSeries(Graphics g, SDAChartSeries series) { SDAChartSeries.PointData pd = null; Font ft = getFont(); int fontHeight = ft.getHeight(); int x1 = 0, y1 = 0; int mack = series.getMarksBackColor(); byte type = series.getMarkValueType(); String value = ""; series.calPercent(); int pieTop = showTitleText ? fontHeight + 8 : 8; int pieWidth = getWidth() - 8 - (series.isShowPieLegend() ? series.getPieLegendWidth() : 0); int pieHeight = getHeight() - pieTop; SetClip(g, 1, pieTop - 2, width, height); double startAngle = 0; double angle = 0; g.setColor(foreColor); fillArc(g, pieWidth / 2 + 4, pieHeight / 2 + pieTop - 2, pieWidth + 2, pieHeight + 2, 0, 360); //图例 if (series.isShowPieLegend()) { g.setColor(foreColor); drawRect(g, pieWidth + 8, pieTop, series.getPieLegendWidth() - 1, series.getDataCount() * fontHeight); } for (int i = 0; i < series.getDataCount(); i++) { pd = series.getData(i); x1 = getXPos(pd.xValue); y1 = getYPos(pd.yValue); //角度 angle = 360 * pd.dpercent / 100; //饼图 g.setColor(pd.color); fillArc(g, pieWidth / 2 + 4, pieHeight / 2 + pieTop - 2, pieWidth, pieHeight, (int) startAngle, (int) angle + 1); startAngle += angle; //画标识 if (series.isShowPieLegend()) { if (type == SDAChartSeries.svNone) { value = ""; } if (type == SDAChartSeries.svValue) { value = String.valueOf(pd.yValue); } if (type == SDAChartSeries.svXValue) { value = String.valueOf(pd.xValue); } if (type == SDAChartSeries.svPercent) { value = pd.percent; } if (type == SDAChartSeries.svXYValue) { value = pd.xValue + "/" + pd.yValue; } if (type == SDAChartSeries.svXValuePercent) { value = pd.xValue + "/" + pd.percent; } if (type == SDAChartSeries.svLabel) { value = pd.label; } if (type == SDAChartSeries.svLabelValue) { value = pd.label + "/" + pd.yValue; } if (type == SDAChartSeries.svLabelPercent) { value = pd.label + "/" + pd.percent; } if (value.length() > 0) { g.setColor(pd.color); fillRect(g, pieWidth + 10, pieTop + 1 + i * fontHeight + (fontHeight - 8) / 2, 8, 8); g.setColor(foreColor); drawRect(g, pieWidth + 10, pieTop + 1 + i * fontHeight + (fontHeight - 8) / 2, 8, 8); g.setColor(foreColor); drawString(g, value, pieWidth + 20, pieTop + 1 + i * fontHeight); } } } } //根据点得到实际位置 private int getXPos(double x) { return (int) (xStartPos + (x - minXValue) * xLen / (maxXValue - minXValue)); } private int getYPos(double y) { return (int) (yStartPos - (y - minYValue) * yLen / (maxYValue - minYValue)) + 1; } //图表增加删除 public void addSeries(SDAChartSeries series) { if (!seriesList.contains(series)) { seriesList.addElement(series); series.setChart(this); repaintControl(); } } public void removeSeries(SDAChartSeries series) { if (seriesList.contains(series)) { seriesList.removeElement(series); repaintControl(); } } public void removeSeries(int index) { if (index > -1 && index < seriesList.size()) { seriesList.removeElementAt(index); repaintControl(); } } //属性 public String getAxisText() { return axisText; } public void setAxisText(String axisText) { this.axisText = axisText; } public int getAxisTextAlign() { return axisTextAlign; } public void setAxisTextAlign(int axisTextAlign) { this.axisTextAlign = axisTextAlign; } public int getBorderColor() { return borderColor; } public void setBorderColor(int borderColor) { this.borderColor = borderColor; } public String getFootText() { return footText; } public void setFootText(String footText) { this.footText = footText; } public int getFootTextAlign() { return footTextAlign; } public void setFootTextAlign(int footTextAlign) { this.footTextAlign = footTextAlign; } public int getScaleLineColor() { return scaleLineColor; } public void setScaleLineColor(int scaleLineColor) { this.scaleLineColor = scaleLineColor; } public String getTitleText() { return titleText; } public void setTitleText(String titleText) { this.titleText = titleText; } public int getTitleTextAlign() { return titleTextAlign; } public void setTitleTextAlign(int titleTextAlign) { this.titleTextAlign = titleTextAlign; } public boolean isShowAxisText() { return showAxisText; } public void setShowAxisText(boolean showAxisText) { this.showAxisText = showAxisText; } public boolean isShowFootText() { return showFootText; } public void setShowFootText(boolean showFootText) { this.showFootText = showFootText; } public boolean isShowTitleText() { return showTitleText; } public void setShowTitleText(boolean showTitleText) { this.showTitleText = showTitleText; } public int getRefLineColor() { return refLineColor; } public void setRefLineColor(int refLineColor) { this.refLineColor = refLineColor; } public int getBarChartWidth() { return barChartWidth; } public void setBarChartWidth(int barChartWidth) { this.barChartWidth = barChartWidth; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -