<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jfreechart 學習筆記

    1.java 2D主要繪圖類描述(jdk1.5)
    ?Graphics2D //主要繪圖對象,每種圖形都要通過該對象來繪制
    ?Rectangle2D //長方形對象
    ?Point2D //點對象
    ?Line2D //線對象
    ?Arc2D.Double //弧形對象
    ?Ellipse2D //橢圓對象
    ?Polygon //多邊形對象
    ?Paint //油漆桶對象,用來定義顏色
    ?Stroke //畫筆對象,主要用于描繪輪廓,定義線條樣式
    ?Area //幾何建模對象(含幾何并交差運算等方法)
    ?GeneralPath //路徑對象
    ?
    ?1.1 sample demo eg:
    ??/**
    ?? * 利用路徑對象繪制平面圖
    ?? */
    ??// 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());
    ??// }
    ??
    ??/**
    ?? * 長方形對象加路徑對象繪制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; // 實體顏色
    ??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);
    ??
    ??// 實線條描邊,寬度1.0f
    ??Stroke stroke = new BasicStroke(1.0f);
    ??// g2.setColor(Color.PINK);
    ??// 先設置實體顏色
    ??g2.setPaint(barpaint);
    ??g2.setStroke(stroke);
    ??g2.fill(r2d);
    ??g2.fill(bar3dRight);
    ??g2.fill(bar3dTop);
    ??// 實體填充進繪圖對象以后,在設置輪廓線顏色(其實是上面三個實體以外的所有圖形的顏色)
    ??g2.setPaint(outlinepaint);
    ??g2.draw(r2d);
    ??g2.draw(bar3dRight);
    ??g2.draw(bar3dTop);

    ??/**
    ?? * 利用橢圓對象繪制橢圓
    ?? */
    ??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);

    ??/**
    ?? * 利用弧形對象繪制弧形
    ?? */
    ??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;
    ??// 設置透明度
    ??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);

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

    ??/**
    ?? * 寫字
    ?? */
    ??// 字體設置
    ??Font font = new Font(null, // 字體
    ????Font.ITALIC + Font.BOLD, // 樣式(這里設置了兩種樣式,黑體+斜體)
    ????10); // 大小
    ??g2.setFont(font);
    ??Paint arcpaint3 = Color.BLACK;
    ??g2.setPaint(arcpaint3);
    ??g2.drawString("delphi", // 要寫的字符串
    ????550, // x坐標
    ????150 // y坐標
    ????);
    ????
    ?? /**
    ?? * 利用多邊形對象繪制多邊形
    ?? */
    ??int []xs = new int[] { 600, 620,
    ????640, 620 };
    ??int []ys = new int[] { 100,
    ????100, 150,
    ????150};???
    ??Polygon polygon = new Polygon(
    ????xs, //多邊形x坐標點的數組
    ????ys, //多邊形y坐標點的數組
    ????4 //數組大小
    ????);
    ??g2.setPaint(java.awt.Color.lightGray);
    ??g2.fill(polygon);
    ??g2.draw(polygon);
    ??
    ??/**
    ?? * 畫網格線
    ?? */?
    ??for(double i=0.0; i<450.0; i+=30.0){
    ???// 網格線樣式
    ????? 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屬性來區別的
    ?BarRenderer //2DBarRenderer
    ?BarRenderer3D //3DBarRenderer
    ?CategoryPlot plot = new CategoryPlot(
    ??????????? dataset, categoryAxis, valueAxis, renderer
    ??????? );

    3.3D餅圖的繪制函數(現在的注釋還不夠全面,也可能存在錯誤)
    ?/**
    ? * 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坐標大小
    ??double linkX = plotArea.getX() + gapHorizontal / 2;
    ??// y坐標大小
    ??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);
    ??// 定義橢圓中心點
    ??state.setPieCenterX(pieArea.getCenterX());
    ??state.setPieCenterY(pieArea.getCenterY() - depth / 2.0);
    ??// 定義橢圓寬的半徑
    ??state.setPieWRadius(pieArea.getWidth() / 2.0);
    ??// 定義橢圓高的半徑
    ??state.setPieHRadius((pieArea.getHeight() - depth) / 2.0);
    ??// 畫背景長方形(500*300)區域
    ??drawBackground(g2, plotArea);
    ??// 獲取外面傳進來3D餅圖的數據源
    ??PieDataset dataset = getDataset();??
    ??// 如果數據源為空則直接返回,整個圖表就一個背景長方形沒有數據圖形
    ??if (DatasetUtilities.isEmptyOrNull(getDataset())) {
    ???drawNoDataMessage(g2, plotArea);
    ???g2.setClip(savedClip);
    ???drawOutline(g2, plotArea);
    ???return;
    ??}

    ??/**
    ?? * 如果數據源的主鍵的個數大于圖形區域的寬度,則在圖形上顯示"Too many elements" 數據源示例如下: 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;
    ?? * 這個數據源的主鍵的個數為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.
    ??// 如果我們畫的是一個圓形那只要知道圖形的左邊距,上邊距,和直徑
    ??if (isCircular()) {
    ???// 圓形半徑(取寬高中的小的那個數的一半)
    ???double min = Math.min(plotArea.getWidth(), plotArea.getHeight()) / 2;
    ???plotArea = new Rectangle2D.Double(
    ?????plotArea.getCenterX() - min, //左邊距(新的圖形的中心點x坐標)
    ?????plotArea.getCenterY() - min, //上邊距(新的圖形的中心點y坐標)
    ?????2 * min, //直徑(圖形的寬度)
    ?????2 * min //直徑(圖形的高度)
    ?????);
    ??}
    ??
    ??// 獲取數據源主鍵列表
    ??List sectionKeys = dataset.getKeys();
    ??// 如果數據源主鍵列表為空,退出
    ??if (sectionKeys.size() == 0) {
    ???return;
    ??}

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

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

    ??//弧形的列表(用于添加主鍵的值對應的弧形)
    ??ArrayList arcList = new ArrayList();
    ??//定義一個弧行
    ??Arc2D.Double arc;
    ??//定義油漆桶,用來填充顏色
    ??Paint paint;
    ??Paint outlinePaint;
    ??//用于描繪輪廓的樣式
    ??Stroke outlineStroke;
    ??
    ??//遍歷取出主鍵的值對應的弧形放到弧形列表
    ??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;
    ???}
    ???
    ???//弧形的開始角度(從該角度算起,相當于360度的0度)
    ???double startAngle = getStartAngle();
    ???//方向
    ???double direction = getDirection().getFactor();
    ???//角度大小1(該主鍵對應的弧形的開始角度)
    ???double angle1 = startAngle + (direction * (runningTotal * 360))
    ?????/ totalValue;
    ???//角度大小2(該主鍵對應的弧形的結束角度)
    ???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);
    ???}
    ???
    ???//轉入下個弧形(主鍵對應的圖形)
    ???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);??
    ??//底部的長方形
    ??Rectangle2D lower = new Rectangle2D.Double(top.getX(),
    ????top.getCenterY(), pieArea.getWidth(), bottom.getMaxY()
    ??????- top.getCenterY());
    ??//上部的長方形
    ??Rectangle2D upper = new Rectangle2D.Double(pieArea.getX(), top.getY(),
    ????pieArea.getWidth(), bottom.getCenterY() - top.getY());
    ??
    ??// Area幾何建模對象
    ??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);
    ??// 通過幾何建模對象對上面的圖形進行交叉運算
    ??pie.intersect(b);

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

    ??Area back = new Area(pie);
    ??// 相減運算
    ??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);
    ???
    ???//取得弧形的開始點
    ???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坐標點的數組
    ?????ys, //多邊形y坐標點的數組
    ?????4 //數組大小
    ?????);
    ???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餅圖上部的橢圓的弧形和相關的標簽鏈接和底部的說明(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圖形對象所需的油漆桶
    ???paint = getSectionPaint(sectionIndex);
    ???//g2圖形對象所需的輪廓油漆桶
    ???outlinePaint = getSectionOutlinePaint(sectionIndex);
    ???//g2圖形對象所需的輪廓樣式
    ???outlineStroke = getSectionOutlineStroke(sectionIndex);
    ???g2.setPaint(paint);
    ???//往g2圖形對象中填充弧形
    ???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();
    ???//繪制標簽的長方形
    ???Rectangle2D adjustedPlotArea = new Rectangle2D.Double(
    ?????originalPlotArea.getX(), originalPlotArea.getY(),
    ?????originalPlotArea.getWidth(), originalPlotArea.getHeight()
    ???????- depth);
    ???//繪制標簽(如:Perl=1的Textbox)
    ???drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state);
    ??}

    ??g2.setClip(savedClip);
    ??g2.setComposite(originalComposite);
    ??//繪制輪廓
    ??drawOutline(g2, originalPlotArea);
    ?}
    ?
    4.3D柱狀圖的繪制函數(現在的注釋還不夠全面,也可能存在錯誤)
    ??? /**
    ???? * 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);

    ??????? // 柱子的俯視圖上的四個點的x坐標值
    ??????? double x0 = bar.getMinX();
    ??????? double x1 = x0 + getXOffset(); //x0+12
    ??????? double x2 = bar.getMaxX();
    ??????? double x3 = x2 + getXOffset(); //x2+12
    ??????? // 柱子的右視圖上的四個點的y坐標值
    ??????? 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);
    ??????????? }
    ??????? }

    ??????? //繪制標簽
    ??????? 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編程隨筆 閱讀(1473) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2006年5月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    導航

    統計

    常用鏈接

    留言簿(1)

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲精品乱码久久久久久V| 亚洲精品高清无码视频| 亚洲视频在线不卡| 免费无码又爽又刺激高潮软件| 国产一区二区三区免费视频| 亚洲一线产品二线产品| 亚洲中文无码永久免费| 亚洲一区二区三区深夜天堂| 曰批全过程免费视频在线观看 | 免费夜色污私人影院在线观看| 国产成人精品日本亚洲直接 | 亚洲人配人种jizz| 岛国av无码免费无禁网站| 亚洲一区AV无码少妇电影| 日韩电影免费在线| 麻豆91免费视频| 亚洲中文字幕无码日韩| 精品视频一区二区三区免费| 亚洲精品自产拍在线观看动漫| 99精品视频免费在线观看| 亚洲视屏在线观看| 日韩人妻无码免费视频一区二区三区 | 亚洲三级在线播放| 大陆一级毛片免费视频观看| 久久久久亚洲国产AV麻豆| 免费国产真实迷j在线观看| 最新久久免费视频| 亚洲精品国产啊女成拍色拍| 免费做爰猛烈吃奶摸视频在线观看| 亚洲国产成人精品无码区二本| 亚洲福利精品电影在线观看| 国产情侣久久久久aⅴ免费| 亚洲成人在线免费观看| 国产成人无码区免费A∨视频网站| 9久热精品免费观看视频| 亚洲黄色在线观看| 国产乱色精品成人免费视频| 亚洲高清免费视频| 亚洲国产日产无码精品| 免费A级毛片无码A| 亚洲人成免费网站|