jfreechart 學(xué)習(xí)筆記

          1.java 2D主要繪圖類描述(jdk1.5)
          ?Graphics2D //主要繪圖對(duì)象,每種圖形都要通過該對(duì)象來繪制
          ?Rectangle2D //長(zhǎng)方形對(duì)象
          ?Point2D //點(diǎn)對(duì)象
          ?Line2D //線對(duì)象
          ?Arc2D.Double //弧形對(duì)象
          ?Ellipse2D //橢圓對(duì)象
          ?Polygon //多邊形對(duì)象
          ?Paint //油漆桶對(duì)象,用來定義顏色
          ?Stroke //畫筆對(duì)象,主要用于描繪輪廓,定義線條樣式
          ?Area //幾何建模對(duì)象(含幾何并交差運(yùn)算等方法)
          ?GeneralPath //路徑對(duì)象
          ?
          ?1.1 sample demo eg:
          ??/**
          ?? * 利用路徑對(duì)象繪制平面圖
          ?? */
          ??// GeneralPath bar3dRight = new GeneralPath();
          ??// bar3dRight.moveTo((float) 100.0, (float) 100.0);
          ??// bar3dRight.lineTo((float) 200.0, (float) 200.0);
          ??// bar3dRight.lineTo((float) 300.0, (float) 100.0);
          ??// bar3dRight.lineTo((float) 100.0, (float) 100.0);
          ??// bar3dRight.closePath();
          ??// 填充四邊形的顏色
          ??// if (itemPaint instanceof Color) {
          ??// g2.setPaint(((Color) itemPaint).darker());
          ??// }
          ??
          ??/**
          ?? * 長(zhǎng)方形對(duì)象加路徑對(duì)象繪制3D柱狀圖
          ?? */
          ??//正視圖
          ??Rectangle2D r2d = new Rectangle2D.Double(
          ????100.0, //x
          ????100.0, //y
          ????30.0, //width
          ????200.0 //hight
          ????);
          ??//右視圖
          ??GeneralPath bar3dRight = new GeneralPath();
          ??bar3dRight.moveTo((float) 130.0, (float) 100.0);
          ??bar3dRight.lineTo((float) 150.0, (float) 90.0);
          ??bar3dRight.lineTo((float) 150.0, (float) 290.0);
          ??bar3dRight.lineTo((float) 130.0, (float) 300.0);
          ??bar3dRight.closePath();
          ??//俯視圖
          ??GeneralPath bar3dTop = new GeneralPath();
          ??bar3dTop.moveTo((float) 100.0, (float) 100.0);
          ??bar3dTop.lineTo((float) 130.0, (float) 100.0);
          ??bar3dTop.lineTo((float) 150.0, (float) 90.0);
          ??bar3dTop.lineTo((float) 120.0, (float) 90.0);
          ??bar3dTop.closePath();
          ??Paint barpaint = Color.PINK; // 實(shí)體顏色
          ??Paint outlinepaint = Color.DARK_GRAY; // 輪廓線顏色
          ??float dash1[] = { 10.0f };
          ??// 虛線條描邊
          ??// Stroke stroke = new BasicStroke(1.0f,
          ??// BasicStroke.CAP_BUTT,
          ??// BasicStroke.JOIN_MITER,
          ??// 10.0f, dash1, 0.0f);
          ??
          ??// 實(shí)線條描邊,寬度1.0f
          ??Stroke stroke = new BasicStroke(1.0f);
          ??// g2.setColor(Color.PINK);
          ??// 先設(shè)置實(shí)體顏色
          ??g2.setPaint(barpaint);
          ??g2.setStroke(stroke);
          ??g2.fill(r2d);
          ??g2.fill(bar3dRight);
          ??g2.fill(bar3dTop);
          ??// 實(shí)體填充進(jìn)繪圖對(duì)象以后,在設(shè)置輪廓線顏色(其實(shí)是上面三個(gè)實(shí)體以外的所有圖形的顏色)
          ??g2.setPaint(outlinepaint);
          ??g2.draw(r2d);
          ??g2.draw(bar3dRight);
          ??g2.draw(bar3dTop);

          ??/**
          ?? * 利用橢圓對(duì)象繪制橢圓
          ?? */
          ??Ellipse2D ellipse2D = new Ellipse2D.Double(200.0, // x
          ????100.0, // y
          ????200.0, // width
          ????200.0 // hight
          ??);
          ??Paint ellipsepaint = Color.blue;
          ??g2.setPaint(ellipsepaint);
          ??g2.fill(ellipse2D);
          ??g2.draw(ellipse2D);

          ??/**
          ?? * 利用弧形對(duì)象繪制弧形
          ?? */
          ??Arc2D.Double arc = new Arc2D.Double(350.0, // x
          ????100.0, // y
          ????200.0, // width
          ????200.0, // hight
          ????0.0, // start angle
          ????90.0, // arc angle
          ????Arc2D.PIE // pie:3.1415926
          ??);
          ??Arc2D.Double arc2 = new Arc2D.Double(350.0, // x
          ????100.0, // y
          ????200.0, // width
          ????200.0, // hight
          ????-60.0, // start angle
          ????90.0, // arc angle
          ????Arc2D.PIE // pie:3.1415926
          ??);
          ??Paint arcpaint1 = Color.GREEN;
          ??Paint arcpaint2 = Color.RED;
          ??// 設(shè)置透明度
          ??g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
          ????0.3f));
          ??g2.setPaint(arcpaint1);
          ??g2.fill(arc);
          ??g2.draw(arc);
          ??g2.setPaint(arcpaint2);
          ??g2.fill(arc2);
          ??g2.draw(arc2);

          ??/**
          ?? * 圖形的幾何運(yùn)算
          ?? */
          ??// Area a = new Area(arc);
          ??// Area b = new Area(arc2);
          ??// ab交差運(yùn)算,去掉兩個(gè)圖形相交的部分得到的圖形
          ??// a.exclusiveOr(b);
          ??// a交b運(yùn)算
          ??// a.intersect(b);
          ??// a減去b運(yùn)算,即差運(yùn)算
          ??// a.subtract(b);
          ??// a并b運(yùn)算
          ??// a.add(b);
          ??// g2.setPaint(arcpaint2);
          ??// g2.fill(a);
          ??// g2.draw(a);
          ??
          ??/**
          ?? * 利用jfreechart的TextBox對(duì)象繪制文本框
          ?? */
          ??// 設(shè)置透明度為1,也就是不透明了
          ??g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
          ????1.0f));
          ??TextBox textBox = new TextBox("java" // 想要顯示的字符串
          ??);
          ??textBox.draw(g2, // 繪圖對(duì)象
          ????(float) 550.0, // x坐標(biāo)
          ????(float) 100.0, // y坐標(biāo)
          ????RectangleAnchor.CENTER // 對(duì)齊方式
          ????);
          ??Line2D.Double line = new Line2D.Double(522.0, // 線的第一個(gè)點(diǎn)的x坐標(biāo)
          ????100.0, // 線的第一個(gè)點(diǎn)的y坐標(biāo)
          ????500.0, // 線的第二個(gè)點(diǎn)的x坐標(biāo)
          ????120.0 // 線的第二個(gè)點(diǎn)的y坐標(biāo)
          ??);
          ??g2.draw(line);

          ??/**
          ?? * 寫字
          ?? */
          ??// 字體設(shè)置
          ??Font font = new Font(null, // 字體
          ????Font.ITALIC + Font.BOLD, // 樣式(這里設(shè)置了兩種樣式,黑體+斜體)
          ????10); // 大小
          ??g2.setFont(font);
          ??Paint arcpaint3 = Color.BLACK;
          ??g2.setPaint(arcpaint3);
          ??g2.drawString("delphi", // 要寫的字符串
          ????550, // x坐標(biāo)
          ????150 // y坐標(biāo)
          ????);
          ????
          ?? /**
          ?? * 利用多邊形對(duì)象繪制多邊形
          ?? */
          ??int []xs = new int[] { 600, 620,
          ????640, 620 };
          ??int []ys = new int[] { 100,
          ????100, 150,
          ????150};???
          ??Polygon polygon = new Polygon(
          ????xs, //多邊形x坐標(biāo)點(diǎn)的數(shù)組
          ????ys, //多邊形y坐標(biāo)點(diǎn)的數(shù)組
          ????4 //數(shù)組大小
          ????);
          ??g2.setPaint(java.awt.Color.lightGray);
          ??g2.fill(polygon);
          ??g2.draw(polygon);
          ??
          ??/**
          ?? * 畫網(wǎng)格線
          ?? */?
          ??for(double i=0.0; i<450.0; i+=30.0){
          ???// 網(wǎng)格線樣式
          ????? Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f,
          ????????????? BasicStroke.CAP_BUTT,
          ????????????? BasicStroke.JOIN_BEVEL,
          ????????????? 0.0f,
          ????????????? new float[] {2.0f, 2.0f},
          ????????????? 0.0f);
          ????? Line2D.Double gridline = new Line2D.Double(0.0,i+30.0,700.0,i+30.0);
          ????? g2.setPaint(Color.GRAY);
          ????? g2.setStroke(DEFAULT_GRIDLINE_STROKE);
          ????? g2.draw(gridline);
          ??}


          2.柱狀圖2D和3D是通過CategoryPlot的renderer屬性來區(qū)別的
          ?BarRenderer //2DBarRenderer
          ?BarRenderer3D //3DBarRenderer
          ?CategoryPlot plot = new CategoryPlot(
          ??????????? dataset, categoryAxis, valueAxis, renderer
          ??????? );

          3.3D餅圖的繪制函數(shù)(現(xiàn)在的注釋還不夠全面,也可能存在錯(cuò)誤)
          ?/**
          ? * Draws the plot on a Java 2D graphics device (such as the screen or a
          ? * printer). This method is called by the {@link org.jfree.chart.JFreeChart}
          ? * class, you don't normally need to call it yourself.
          ? *
          ? * @param g2
          ? *??????????? the graphics device.
          ? * @param plotArea
          ? *??????????? the area within which the plot should be drawn.
          ? * @param anchor
          ? *??????????? the anchor point.
          ? * @param parentState
          ? *??????????? the state from the parent plot, if there is one.
          ? * @param info
          ? *??????????? collects info about the drawing (<code>null</code>
          ? *??????????? permitted).
          ? */
          ?public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor,
          ???PlotState parentState, PlotRenderingInfo info) {

          ??// adjust for insets...
          ??RectangleInsets insets = getInsets();
          ??insets.trim(plotArea);

          ??Rectangle2D originalPlotArea = (Rectangle2D) plotArea.clone();
          ??if (info != null) {
          ???info.setPlotArea(plotArea);
          ???info.setDataArea(plotArea);
          ??}

          ??Shape savedClip = g2.getClip();
          ??g2.clip(plotArea);

          ??// adjust the plot area by the interior spacing value
          ??double gapPercent = getInteriorGap();
          ??double labelPercent = 0.0;
          ??if (getLabelGenerator() != null) {
          ???labelPercent = getLabelGap() + getMaximumLabelWidth()
          ?????+ getLabelLinkMargin();
          ??}

          ??// 水平方向的間隙
          ??double gapHorizontal = plotArea.getWidth()
          ????* (gapPercent + labelPercent);
          ??// 垂直方向的間隙
          ??double gapVertical = plotArea.getHeight() * gapPercent;
          ??// x坐標(biāo)大小
          ??double linkX = plotArea.getX() + gapHorizontal / 2;
          ??// y坐標(biāo)大小
          ??double linkY = plotArea.getY() + gapVertical / 2;
          ??// 圖形寬度
          ??double linkW = plotArea.getWidth() - gapHorizontal;
          ??// 圖形高度
          ??double linkH = plotArea.getHeight() - gapVertical;

          ??// make the link area a square if the pie chart is to be circular...
          ??if (isCircular()) { // is circular?
          ???double min = Math.min(linkW, linkH) / 2;
          ???linkX = (linkX + linkX + linkW) / 2 - min;
          ???linkY = (linkY + linkY + linkH) / 2 - min;
          ???linkW = 2 * min;
          ???linkH = 2 * min;
          ??}

          ??PiePlotState state = initialise(g2, plotArea, this, null, info);
          ??// the explode area defines the max circle/ellipse for the exploded pie
          ??// sections.
          ??// it is defined by shrinking the linkArea by the linkMargin factor.
          ??double hh = linkW * getLabelLinkMargin();
          ??double vv = linkH * getLabelLinkMargin();
          ??Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0,
          ????linkY + vv / 2.0, linkW - hh, linkH - vv);

          ??state.setExplodedPieArea(explodeArea);

          ??// the pie area defines the circle/ellipse for regular pie sections.
          ??// it is defined by shrinking the explodeArea by the explodeMargin
          ??// factor.
          ??double maximumExplodePercent = getMaximumExplodePercent();
          ??double percent = maximumExplodePercent / (1.0 + maximumExplodePercent);

          ??double h1 = explodeArea.getWidth() * percent;
          ??double v1 = explodeArea.getHeight() * percent;
          ??Rectangle2D pieArea = new Rectangle2D.Double(explodeArea.getX() + h1
          ????/ 2.0, explodeArea.getY() + v1 / 2.0, explodeArea.getWidth()
          ????- h1, explodeArea.getHeight() - v1);

          ??// 定義3D橢圓的高度
          ??int depth = (int) (pieArea.getHeight() * this.depthFactor);
          ??// the link area defines the dog-leg point for the linking lines to
          ??// the labels
          ??Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW,
          ????linkH - depth);
          ??state.setLinkArea(linkArea);

          ??state.setPieArea(pieArea);
          ??// 定義橢圓中心點(diǎn)
          ??state.setPieCenterX(pieArea.getCenterX());
          ??state.setPieCenterY(pieArea.getCenterY() - depth / 2.0);
          ??// 定義橢圓寬的半徑
          ??state.setPieWRadius(pieArea.getWidth() / 2.0);
          ??// 定義橢圓高的半徑
          ??state.setPieHRadius((pieArea.getHeight() - depth) / 2.0);
          ??// 畫背景長(zhǎng)方形(500*300)區(qū)域
          ??drawBackground(g2, plotArea);
          ??// 獲取外面?zhèn)鬟M(jìn)來3D餅圖的數(shù)據(jù)源
          ??PieDataset dataset = getDataset();??
          ??// 如果數(shù)據(jù)源為空則直接返回,整個(gè)圖表就一個(gè)背景長(zhǎng)方形沒有數(shù)據(jù)圖形
          ??if (DatasetUtilities.isEmptyOrNull(getDataset())) {
          ???drawNoDataMessage(g2, plotArea);
          ???g2.setClip(savedClip);
          ???drawOutline(g2, plotArea);
          ???return;
          ??}

          ??/**
          ?? * 如果數(shù)據(jù)源的主鍵的個(gè)數(shù)大于圖形區(qū)域的寬度,則在圖形上顯示"Too many elements" 數(shù)據(jù)源示例如下: final
          ?? * DefaultPieDataset result = new DefaultPieDataset();
          ?? * result.setValue("Java", new Double(43.2));
          ?? * result.setValue("VisualBasic", new Double(10.0));
          ?? * result.setValue("C/C++", new Double(17.5));
          ?? * result.setValue("PHP", new Double(32.5));
          ?? * result.setValue("Perl", new Double(1.0));
          ?? * return result;
          ?? * 這個(gè)數(shù)據(jù)源的主鍵的個(gè)數(shù)為5
          ?? */
          ??if (dataset.getKeys().size() > plotArea.getWidth()) {
          ???String text = "Too many elements";
          ???Font sfont = new Font("dialog", Font.BOLD, 10);
          ???g2.setFont(sfont);
          ???FontMetrics fm = g2.getFontMetrics(sfont);
          ???int stringWidth = fm.stringWidth(text);

          ???g2
          ?????.drawString(text, (int) (plotArea.getX() + (plotArea
          ???????.getWidth() - stringWidth) / 2), (int) (plotArea
          ???????.getY() + (plotArea.getHeight() / 2)));
          ???return;
          ??}
          ??
          ??// if we are drawing a perfect circle, we need to readjust the top left
          ??// coordinates of the drawing area for the arcs to arrive at this
          ??// effect.
          ??// 如果我們畫的是一個(gè)圓形那只要知道圖形的左邊距,上邊距,和直徑
          ??if (isCircular()) {
          ???// 圓形半徑(取寬高中的小的那個(gè)數(shù)的一半)
          ???double min = Math.min(plotArea.getWidth(), plotArea.getHeight()) / 2;
          ???plotArea = new Rectangle2D.Double(
          ?????plotArea.getCenterX() - min, //左邊距(新的圖形的中心點(diǎn)x坐標(biāo))
          ?????plotArea.getCenterY() - min, //上邊距(新的圖形的中心點(diǎn)y坐標(biāo))
          ?????2 * min, //直徑(圖形的寬度)
          ?????2 * min //直徑(圖形的高度)
          ?????);
          ??}
          ??
          ??// 獲取數(shù)據(jù)源主鍵列表
          ??List sectionKeys = dataset.getKeys();
          ??// 如果數(shù)據(jù)源主鍵列表為空,退出
          ??if (sectionKeys.size() == 0) {
          ???return;
          ??}

          ??// establish the coordinates of the top left corner of the drawing area
          ??//確定pieArea區(qū)域的中心點(diǎn)
          ??double arcX = pieArea.getX();
          ??double arcY = pieArea.getY();

          ??// g2.clip(clipArea);
          ??Composite originalComposite = g2.getComposite();
          ??g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
          ????getForegroundAlpha()));
          ??
          ??//把數(shù)據(jù)源每個(gè)主鍵對(duì)應(yīng)的值加起來
          ??double totalValue = DatasetUtilities.calculatePieDatasetTotal(dataset);
          ??
          ??//遍歷列表的時(shí)候用到
          ??double runningTotal = 0;
          ??
          ??//如果高度<0退出
          ??if (depth < 0) {
          ???return; // if depth is negative don't draw anything
          ??}

          ??//弧形的列表(用于添加主鍵的值對(duì)應(yīng)的弧形)
          ??ArrayList arcList = new ArrayList();
          ??//定義一個(gè)弧行
          ??Arc2D.Double arc;
          ??//定義油漆桶,用來填充顏色
          ??Paint paint;
          ??Paint outlinePaint;
          ??//用于描繪輪廓的樣式
          ??Stroke outlineStroke;
          ??
          ??//遍歷取出主鍵的值對(duì)應(yīng)的弧形放到弧形列表
          ??Iterator iterator = sectionKeys.iterator();
          ??while (iterator.hasNext()) {
          ???// 取出主鍵的值
          ???Comparable currentKey = (Comparable) iterator.next();???
          ???Number dataValue = dataset.getValue(currentKey);
          ???
          ???// 如果主鍵的值為空,則弧形為空
          ???if (dataValue == null) {
          ????arcList.add(null);
          ????continue;
          ???}
          ???
          ???// 如果主鍵的值<=0,則弧形為空
          ???double value = dataValue.doubleValue();
          ???if (value <= 0) {
          ????arcList.add(null);
          ????continue;
          ???}
          ???
          ???//弧形的開始角度(從該角度算起,相當(dāng)于360度的0度)
          ???double startAngle = getStartAngle();
          ???//方向
          ???double direction = getDirection().getFactor();
          ???//角度大小1(該主鍵對(duì)應(yīng)的弧形的開始角度)
          ???double angle1 = startAngle + (direction * (runningTotal * 360))
          ?????/ totalValue;
          ???//角度大小2(該主鍵對(duì)應(yīng)的弧形的結(jié)束角度)
          ???double angle2 = startAngle
          ?????+ (direction * (runningTotal + value) * 360) / totalValue;
          ???
          ???//如果弧形的角度大小<0.00001則該弧形為空
          ???if (Math.abs(angle2 - angle1) > getMinimumArcAngleToDraw()) {
          ????arcList.add(new Arc2D.Double(arcX, arcY + depth, pieArea
          ??????.getWidth(), pieArea.getHeight() - depth, angle1,
          ??????angle2 - angle1, Arc2D.PIE));
          ???} else {
          ????arcList.add(null);
          ???}
          ???
          ???//轉(zhuǎn)入下個(gè)弧形(主鍵對(duì)應(yīng)的圖形)
          ???runningTotal += value;
          ??}
          ??
          ??//取出剪裁的圖形(500*300)
          ??Shape oldClip = g2.getClip();

          ??//3D餅圖中上面的橢圓
          ??Ellipse2D top = new Ellipse2D.Double(pieArea.getX(), pieArea.getY(),
          ????pieArea.getWidth(), pieArea.getHeight() - depth);
          ??// 3D餅圖中底部的橢圓
          ??Ellipse2D bottom = new Ellipse2D.Double(pieArea.getX(), pieArea.getY()
          ????+ depth, pieArea.getWidth(), pieArea.getHeight() - depth);??
          ??//底部的長(zhǎng)方形
          ??Rectangle2D lower = new Rectangle2D.Double(top.getX(),
          ????top.getCenterY(), pieArea.getWidth(), bottom.getMaxY()
          ??????- top.getCenterY());
          ??//上部的長(zhǎng)方形
          ??Rectangle2D upper = new Rectangle2D.Double(pieArea.getX(), top.getY(),
          ????pieArea.getWidth(), bottom.getCenterY() - top.getY());
          ??
          ??// Area幾何建模對(duì)象
          ??Area a = new Area(top);
          ??a.add(new Area(lower));
          ??Area b = new Area(bottom);
          ??b.add(new Area(upper));
          ??Area pie = new Area(a);
          ??// 通過幾何建模對(duì)象對(duì)上面的圖形進(jìn)行交叉運(yùn)算
          ??pie.intersect(b);

          ??Area front = new Area(pie);
          ??// 相減運(yùn)算
          ??front.subtract(new Area(top));

          ??Area back = new Area(pie);
          ??// 相減運(yùn)算
          ??back.subtract(new Area(bottom));

          ??// draw the bottom circle
          ??int[] xs;
          ??int[] ys;
          ??outlinePaint = getSectionOutlinePaint(0);
          ??arc = new Arc2D.Double(arcX, arcY + depth, pieArea.getWidth(), pieArea
          ????.getHeight()
          ????- depth, 0, 360, Arc2D.PIE);

          ??// 畫出3D餅圖下部的橢圓的弧形和有該圖形的高度組成的多邊形
          ??int categoryCount = arcList.size();
          ??for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++) {
          ???//取出弧形
          ???arc = (Arc2D.Double) arcList.get(categoryIndex);
          ???if (arc == null) {
          ????continue;
          ???}
          ???paint = getSectionPaint(categoryIndex);
          ???outlinePaint = getSectionOutlinePaint(categoryIndex);
          ???outlineStroke = getSectionOutlineStroke(categoryIndex);
          ???g2.setPaint(paint);
          ???//填充弧形
          ???g2.fill(arc);
          ???g2.setPaint(outlinePaint);
          ???g2.setStroke(outlineStroke);
          ???//繪制弧形
          ???g2.draw(arc);
          ???g2.setPaint(paint);
          ???
          ???//取得弧形的開始點(diǎn)
          ???Point2D p1 = arc.getStartPoint();

          ???// 定義多邊形(弧形的高度組成的圖形)
          ???xs = new int[] { (int) arc.getCenterX(), (int) arc.getCenterX(),
          ?????(int) p1.getX(), (int) p1.getX() };
          ???ys = new int[] { (int) arc.getCenterY(),
          ?????(int) arc.getCenterY() - depth, (int) p1.getY() - depth,
          ?????(int) p1.getY() };???
          ???Polygon polygon = new Polygon(
          ?????xs, //多邊形x坐標(biāo)點(diǎn)的數(shù)組
          ?????ys, //多邊形y坐標(biāo)點(diǎn)的數(shù)組
          ?????4 //數(shù)組大小
          ?????);
          ???g2.setPaint(java.awt.Color.lightGray);
          ???g2.fill(polygon);
          ???g2.setPaint(outlinePaint);
          ???g2.setStroke(outlineStroke);
          ???//繪制該多邊形
          ???g2.draw(polygon);
          ???g2.setPaint(paint);

          ??}

          ??g2.setPaint(Color.gray);
          ??g2.fill(back);
          ??g2.fill(front);

          ??// cycle through once drawing only the sides at the back...
          ??// 描出背部的邊
          ??int cat = 0;
          ??iterator = arcList.iterator();
          ??while (iterator.hasNext()) {
          ???Arc2D segment = (Arc2D) iterator.next();
          ???if (segment != null) {
          ????paint = getSectionPaint(cat);
          ????outlinePaint = getSectionOutlinePaint(cat);
          ????outlineStroke = getSectionOutlineStroke(cat);
          ????drawSide(g2, pieArea, segment, front, back, paint,
          ??????outlinePaint, outlineStroke, false, true);
          ???}
          ???cat++;
          ??}

          ??// cycle through again drawing only the sides at the front...
          ??// 描出前面的邊
          ??cat = 0;
          ??iterator = arcList.iterator();
          ??while (iterator.hasNext()) {
          ???Arc2D segment = (Arc2D) iterator.next();
          ???if (segment != null) {
          ????paint = getSectionPaint(cat);
          ????outlinePaint = getSectionOutlinePaint(cat);
          ????outlineStroke = getSectionOutlineStroke(cat);
          ????drawSide(g2, pieArea, segment, front, back, paint,
          ??????outlinePaint, outlineStroke, true, false);
          ???}
          ???cat++;
          ??}

          ??g2.setClip(oldClip);

          ??// 畫出3D餅圖上部的橢圓的弧形和相關(guān)的標(biāo)簽鏈接和底部的說明(tooltip)
          ??Arc2D upperArc;
          ??for (int sectionIndex = 0; sectionIndex < categoryCount; sectionIndex++) {
          ???//取出弧形
          ???arc = (Arc2D.Double) arcList.get(sectionIndex);
          ???if (arc == null) {
          ????continue;
          ???}
          ???//定義3D餅圖上部的橢圓的弧形
          ???upperArc = new Arc2D.Double(arcX, arcY, pieArea.getWidth(), pieArea
          ?????.getHeight()
          ?????- depth,
          ?????arc.getAngleStart(), //開始角度
          ?????arc.getAngleExtent(), //角度大小
          ?????Arc2D.PIE);
          ???//g2圖形對(duì)象所需的油漆桶
          ???paint = getSectionPaint(sectionIndex);
          ???//g2圖形對(duì)象所需的輪廓油漆桶
          ???outlinePaint = getSectionOutlinePaint(sectionIndex);
          ???//g2圖形對(duì)象所需的輪廓樣式
          ???outlineStroke = getSectionOutlineStroke(sectionIndex);
          ???g2.setPaint(paint);
          ???//往g2圖形對(duì)象中填充弧形
          ???g2.fill(upperArc);
          ???g2.setStroke(outlineStroke);
          ???g2.setPaint(outlinePaint);
          ???//繪制弧形
          ???g2.draw(upperArc);

          ???// 為該部分弧形添加說明欄(tooltip)和url鏈接
          ???Comparable currentKey = (Comparable) sectionKeys.get(sectionIndex);
          ???if (info != null) {
          ????EntityCollection entities = info.getOwner()
          ??????.getEntityCollection();
          ????if (entities != null) {
          ?????String tip = null;
          ?????PieToolTipGenerator tipster = getToolTipGenerator();
          ?????if (tipster != null) {
          ??????// @mgs: using the method's return value was missing
          ??????tip = tipster.generateToolTip(dataset, currentKey);
          ?????}
          ?????String url = null;
          ?????if (getURLGenerator() != null) {
          ??????url = getURLGenerator().generateURL(dataset,
          ????????currentKey, getPieIndex());
          ?????}
          ?????PieSectionEntity entity = new PieSectionEntity(upperArc,
          ???????dataset, getPieIndex(), sectionIndex, currentKey,
          ???????tip, url);
          ?????entities.add(entity);
          ????}
          ???}
          ???
          ???List keys = dataset.getKeys();
          ???//繪制標(biāo)簽的長(zhǎng)方形
          ???Rectangle2D adjustedPlotArea = new Rectangle2D.Double(
          ?????originalPlotArea.getX(), originalPlotArea.getY(),
          ?????originalPlotArea.getWidth(), originalPlotArea.getHeight()
          ???????- depth);
          ???//繪制標(biāo)簽(如:Perl=1的Textbox)
          ???drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state);
          ??}

          ??g2.setClip(savedClip);
          ??g2.setComposite(originalComposite);
          ??//繪制輪廓
          ??drawOutline(g2, originalPlotArea);
          ?}
          ?
          4.3D柱狀圖的繪制函數(shù)(現(xiàn)在的注釋還不夠全面,也可能存在錯(cuò)誤)
          ??? /**
          ???? * Draws a 3D bar to represent one data item.
          ???? *
          ???? * @param g2? the graphics device.
          ???? * @param state? the renderer state.
          ???? * @param dataArea? the area for plotting the data.
          ???? * @param plot? the plot.
          ???? * @param domainAxis? the domain axis.
          ???? * @param rangeAxis? the range axis.
          ???? * @param dataset? the dataset.
          ???? * @param row? the row index (zero-based).
          ???? * @param column? the column index (zero-based).
          ???? * @param pass? the pass index.
          ???? */
          ??? public void drawItem(Graphics2D g2,
          ???????????????????????? CategoryItemRendererState state,
          ???????????????????????? Rectangle2D dataArea,
          ???????????????????????? CategoryPlot plot,
          ???????????????????????? CategoryAxis domainAxis,
          ???????????????????????? ValueAxis rangeAxis,
          ???????????????????????? CategoryDataset dataset,
          ???????????????????????? int row,
          ???????????????????????? int column,
          ???????????????????????? int pass) {
          ???
          ??????? // check the value we are plotting...
          ??????? Number dataValue = dataset.getValue(row, column);
          ??????? if (dataValue == null) {
          ??????????? return;
          ??????? }
          ???????
          ??????? double value = dataValue.doubleValue();
          ???????
          ??????? Rectangle2D adjusted = new Rectangle2D.Double(
          ??????????? dataArea.getX(),
          ??????????? dataArea.getY() + getYOffset(),
          ??????????? dataArea.getWidth() - getXOffset(),
          ??????????? dataArea.getHeight() - getYOffset()
          ??????? );

          ??????? PlotOrientation orientation = plot.getOrientation();
          ???????
          ??????? double barW0 = calculateBarW0(
          ??????????? plot, orientation, adjusted, domainAxis, state, row, column
          ??????? );
          ??????? double[] barL0L1 = calculateBarL0L1(value);
          ??????? if (barL0L1 == null) {
          ??????????? return;? // the bar is not visible
          ??????? }

          ??????? RectangleEdge edge = plot.getRangeAxisEdge();
          ??????? double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
          ??????? double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
          ??????? double barL0 = Math.min(transL0, transL1);
          ??????? double barLength = Math.abs(transL1 - transL0);
          ???????
          ??????? // draw the bar...
          ??????? //柱子的正視圖
          ??????? Rectangle2D bar = null;
          ??????? if (orientation == PlotOrientation.HORIZONTAL) {
          ??????????? bar = new Rectangle2D.Double(
          ??????????????? barL0, barW0, barLength, state.getBarWidth()
          ??????????? );
          ??????? }
          ??????? else {
          ??????????? bar = new Rectangle2D.Double(
          ??????????????? barW0, barL0, state.getBarWidth(), barLength
          ??????????? );
          ??????? }
          ??????? Paint itemPaint = getItemPaint(row, column);
          ??????? g2.setPaint(itemPaint);
          ??????? g2.fill(bar);

          ??????? // 柱子的俯視圖上的四個(gè)點(diǎn)的x坐標(biāo)值
          ??????? double x0 = bar.getMinX();
          ??????? double x1 = x0 + getXOffset(); //x0+12
          ??????? double x2 = bar.getMaxX();
          ??????? double x3 = x2 + getXOffset(); //x2+12
          ??????? // 柱子的右視圖上的四個(gè)點(diǎn)的y坐標(biāo)值
          ??????? double y0 = bar.getMinY() - getYOffset(); //正視圖的最小y值-8
          ??????? double y1 = bar.getMinY();
          ??????? double y2 = bar.getMaxY() - getYOffset(); //正視圖的最大y值-8
          ??????? double y3 = bar.getMaxY();
          ???????
          ??????? GeneralPath bar3dRight = null;
          ??????? GeneralPath bar3dTop = null;
          ??????? // 柱子的右視圖
          ??????? if (barLength > 0.0) {
          ??????????? bar3dRight = new GeneralPath();
          ??????????? bar3dRight.moveTo((float) x2, (float) y3);
          ??????????? bar3dRight.lineTo((float) x2, (float) y1);
          ??????????? bar3dRight.lineTo((float) x3, (float) y0);
          ??????????? bar3dRight.lineTo((float) x3, (float) y2);
          ??????????? bar3dRight.closePath();

          ??????????? if (itemPaint instanceof Color) {
          ??????????????? g2.setPaint(((Color) itemPaint).darker());
          ??????????? }
          ??????????? g2.fill(bar3dRight);
          ??????? }
          ??????? // 柱子的俯視圖
          ??????? bar3dTop = new GeneralPath();
          ??????? bar3dTop.moveTo((float) x0, (float) y1);
          ??????? bar3dTop.lineTo((float) x1, (float) y0);
          ??????? bar3dTop.lineTo((float) x3, (float) y0);
          ??????? bar3dTop.lineTo((float) x2, (float) y1);
          ??????? bar3dTop.closePath();
          ??????? g2.fill(bar3dTop);

          ??????? //繪制3D柱狀圖
          ??????? if (isDrawBarOutline()
          ??????????????? && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
          ??????????? g2.setStroke(getItemOutlineStroke(row, column));
          ??????????? g2.setPaint(getItemOutlinePaint(row, column));
          ??????????? g2.draw(bar);
          ??????????? if (bar3dRight != null) {
          ??????????????? g2.draw(bar3dRight);
          ??????????? }
          ??????????? if (bar3dTop != null) {
          ??????????????? g2.draw(bar3dTop);
          ??????????? }
          ??????? }

          ??????? //繪制標(biāo)簽
          ??????? CategoryItemLabelGenerator generator
          ??????????? = getItemLabelGenerator(row, column);
          ??????? if (generator != null && isItemLabelVisible(row, column)) {
          ??????????? drawItemLabel(
          ??????????????? g2, dataset, row, column, plot, generator, bar, (value < 0.0)
          ??????????? );
          ??????? }???????

          ??????? // add an item entity, if this information is being collected
          ??????? EntityCollection entities = state.getEntityCollection();
          ??????? if (entities != null) {
          ??????????? GeneralPath barOutline = new GeneralPath();
          ??????????? barOutline.moveTo((float) x0, (float) y3);
          ??????????? barOutline.lineTo((float) x0, (float) y1);
          ??????????? barOutline.lineTo((float) x1, (float) y0);
          ??????????? barOutline.lineTo((float) x3, (float) y0);
          ??????????? barOutline.lineTo((float) x3, (float) y2);
          ??????????? barOutline.lineTo((float) x2, (float) y3);
          ??????????? barOutline.closePath();
          ??????????? addItemEntity(entities, dataset, row, column, barOutline);
          ??????? }

          ??? }

          posted on 2006-05-12 15:22 JGAO編程隨筆 閱讀(1475) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2006年5月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 漳州市| 油尖旺区| 南京市| 大埔区| 伊春市| 扶风县| 乳源| 滕州市| 玛沁县| 密云县| 涡阳县| 类乌齐县| 太和县| 商河县| 沂源县| 泉州市| 左云县| 枞阳县| 宣恩县| 大新县| 顺昌县| 崇礼县| 健康| 若尔盖县| 肇州县| 达日县| 漳浦县| 大埔区| 嵊州市| 三江| 文成县| 景洪市| 土默特右旗| 仁寿县| 孟津县| 册亨县| 三都| 深水埗区| 鄯善县| 平定县| 大埔区|