⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chart.java

📁 一个完整的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                int i3 = Math.max(dimension1.height, dimension2.height);
                i3 = Math.max(i3, byte0 + 6) + 2;
                j += i3;
            } else
            {
                k += rectangle1.width + 2;
            }
        }

    }

    public synchronized String formatNumber(double d, int i)
    {
        if(i == 0 && d < 1000D && d > -1000D)
            return Math.round(d) + "";
        long l = (long)Math.pow(10D, i);
        long l1 = Math.round(d * (double)l);
        long l2 = Math.abs(l1) % l + l;
        if(d >= 1000000D || d <= -1000000D)
            l2 = l;
        l1 /= l;
        if(numberFormatter == null)
            numberFormatter = NumberFormat.getInstance();
        numberFormatter.setMaximumFractionDigits(0);
        String s = "";
        if(i > 0)
            s = "." + (l2 + "").substring(1);
        String s1 = numberFormatter.format(l1) + s;
        if(d < 0.0D && !s1.startsWith("-", 0))
            s1 = "-" + s1;
        return s1;
    }

    public boolean isLegendOn()
    {
        return legendOn;
    }

    public synchronized void setSeriesLabel(int i, String s)
    {
        chartData.setSeriesLabel(i, s);
        hasChanged = true;
        autoRepaint();
    }

    public synchronized String getSeriesLabel(int i)
    {
        return chartData.getSeriesLabel(i);
    }

    void paintLabel(Graphics g, String s, int i, int j, Dimension dimension, int k, int l)
    {
		//System.out.println("Label="+s+";"+k+"");
       // g.setFont(new Font("黑体", 1, 50));
       //mq modify 2003-12-06
        FontMetrics fontmetrics = g.getFontMetrics();
        if(s != null && l == 0)
        {
            for(StringTokenizer stringtokenizer = new StringTokenizer(s, "\n"); stringtokenizer.hasMoreElements();)
            {
                String s1 = (String)stringtokenizer.nextElement();
             
                if(s1 != null && s1.length() > 0)
                    if(k == -1)
                        g.drawString(s1, i, j);
                    else
                    if(k == 1)
                        g.drawString(s1, (i + dimension.width) - fontmetrics.stringWidth(s1), j);
                    else
                        g.drawString(s1, (i + dimension.width / 2) - fontmetrics.stringWidth(s1) / 2, j);
                j += fontmetrics.getMaxAscent() + 1;
            	//System.out.println("s1="+s1);
            }

        } else
        if(s != null)
        {
            Long long1 = new Long(s.hashCode() + l + g.getFont().hashCode());
            Image image = (Image)angledLabelCache.get(long1);
            if(image == null)
            {
                if(rotateImage == null || dimension.width > rotateImage.getWidth(this) || dimension.height > rotateImage.getHeight(this))
                {
                    if(rotateImage != null)
                        rotateImage.flush();
                    rotateImage = createImage(dimension.width, dimension.height);
                }
                Color acolor[] = new Color[2];
                acolor[1] = g.getColor();
                int ai[] = new int[2];
                getColorPixels(acolor, ai);
                Graphics g1 = rotateImage.getGraphics();
                g1.setColor(acolor[0]);
                g1.fillRect(0, 0, dimension.width, dimension.height);
                g1.setColor(acolor[1]);
                g1.setFont(g.getFont());
                paintLabel(g1, s, 0, (fontmetrics.getMaxAscent() - fontmetrics.getDescent()) + 2, dimension, 0, 0);
                g1.dispose();
                g1 = null;
                int ai1[] = new int[dimension.width * dimension.height];
                PixelGrabber pixelgrabber = new PixelGrabber(rotateImage, 0, 0, dimension.width, dimension.height, ai1, 0, dimension.width);
                pixelgrabber.startGrabbing();
                pixelgrabber.getPixels();
                int i1 = acolor[1].getRGB();
                for(int j1 = 0; j1 < ai1.length; j1++)
                    if(ai1[j1] == ai[0])
                        ai1[j1] = ai[0] & 0xffffff;
                    else
                        ai1[j1] = i1;

                Dimension dimension1 = new Dimension(dimension.width, dimension.height);
                int ai2[] = rotateImage(ai1, l, dimension1, ai[0]);
                image = createImage(new MemoryImageSource(dimension1.width, dimension1.height, ai2, 0, dimension1.width));
                if(!servletModeOn)
                    angledLabelCache.put(long1, image);
            }
            if(l == 180)
                j -= fontmetrics.getAscent() - 2;
            g.drawImage(image, i, j, null);
        }
    }

    void paintGrid(Graphics g, Rectangle rectangle)
    {
        if(depth3d > -1)
        {
            depth3dPoint.x = depth3d;
            depth3dPoint.y = -depth3d;
        }
        Polygon polygon = new Polygon();
        polygon.addPoint(rectangle.x, rectangle.y);
        polygon.addPoint(rectangle.x - depth3dPoint.x, rectangle.y - depth3dPoint.y);
        polygon.addPoint(polygon.xpoints[1], polygon.ypoints[1] + rectangle.height);
        polygon.addPoint(rectangle.x, rectangle.y + rectangle.height);
        polygon.addPoint(rectangle.x, rectangle.y);
        Polygon polygon1 = new Polygon();
        polygon1.addPoint(rectangle.x, rectangle.y + rectangle.height);
        polygon1.addPoint(polygon.xpoints[2], polygon.ypoints[2]);
        polygon1.addPoint(polygon1.xpoints[1] + rectangle.width, polygon1.ypoints[1]);
        polygon1.addPoint(rectangle.x + rectangle.width, rectangle.y + rectangle.height);
        polygon1.addPoint(polygon1.xpoints[0], polygon1.ypoints[0]);
        Color color = getChartBackground();
        g.setColor(color);
        g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
        if(display3dOn)
        {
            g.setColor(gridAlignment != 1 ? color.darker() : color);
            g.fillPolygon(polygon);
            g.setColor(gridAlignment != 0 ? color.darker() : color);
            g.fillPolygon(polygon1);
        }
        g.setColor(chartForeground);
        if(display3dOn)
        {
            g.drawPolygon(polygon);
            g.drawPolygon(polygon1);
        }
        g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
        g.setFont(getFont("rangeLabelFont"));
        FontMetrics fontmetrics = g.getFontMetrics();
        for(int i = rangeOn.length - 1; i >= 0; i--)
            paintRange(g, rectangle, i);

        g.setColor(chartForeground);
        if(getLabel("sampleAxisLabel") != null)
        {
            Dimension dimension = new Dimension();
            if(sampleLabelsOn && barLabelStyle != 1)
            {
                Font font = getFont();
                int k = 0;
                if(chartType.equals("bar"))
                {
                    font = getFont("barLabelFont");
                    k = getLabelAngle("barLabelAngle");
                } else
                if(chartType.equals("line"))
                {
                    font = getFont("sampleLabelFont");
                    k = getLabelAngle("sampleLabelAngle");
                }
                String as[] = barLabels == null ? getSampleLabels() : barLabels;
                for(int i1 = 0; i1 < as.length; i1++)
                {
                    Dimension dimension1 = getLabelSize(as[i1], font);
                    Dimension dimension2 = getAngledLabelSize(dimension1, k);
                    dimension.width = Math.max(dimension.width, dimension2.width);
                    dimension.height = Math.max(dimension.height, dimension2.height);
                }

            }
            String s = getLabel("sampleAxisLabel");
            Font font1 = getFont("sampleAxisLabelFont");
            g.setFont(font1);
            FontMetrics fontmetrics1 = g.getFontMetrics();
            int l = 0;
            int j1 = 0;
            int k1 = getLabelAngle("sampleAxisLabelAngle");
            k1 = gridAlignment != 0 ? 0 : k1;
            Dimension dimension3 = getLabelSize(s, font1);
            Dimension dimension4 = getAngledLabelSize(dimension3, k1);
            if(gridAlignment == 1)
            {
                l = (rectangle.x + rectangle.width / 2) - dimension4.width / 2;
                j1 = rectangle.y + rectangle.height + 7;
                if(k1 % 180 == 0)
                    j1 += fontmetrics1.getMaxAscent() - 2;
                if(display3dOn)
                {
                    l -= depth3dPoint.x;
                    j1 -= depth3dPoint.y;
                }
                if(sampleLabelsOn)
                    j1 += dimension.height + 1;
                if(sampleScrollerOn)
                    j1 += 10;
            } else
            {
                l = rectangle.x - dimension4.width - 5;
                j1 = (rectangle.y + rectangle.height / 2) - dimension4.height / 2;
                if(k1 % 180 == 0)
                    j1 += fontmetrics1.getAscent();
                if(sampleLabelsOn)
                    l -= dimension.width + 4;
                if(display3dOn)
                {
                    j1 -= depth3dPoint.y;
                    l -= depth3dPoint.x;
                }
                if(sampleScrollerOn)
                    l -= 10;
            }
            paintLabel(g, s, l, j1, dimension3, 0, k1);
        }
        for(int j = 0; j < rangeAdjusterOn.length; j++)
            paintRangeAdjuster(g, rectangle, j);

        if(sampleScrollerOn)
            paintSampleScroller(g, rectangle);
    }

    private void itransform(double d, double d1, double d2, double d3, double ad[])
    {
        ad[0] = d * d2 - d1 * d3;
        ad[1] = d * d3 + d1 * d2;
    }

    public void setSampleScrollerOn(boolean flag)
    {
        sampleScrollerOn = flag;
        hasChanged = true;
        autoRepaint();
    }

    protected abstract void calculateChartData(Rectangle rectangle, Rectangle rectangle1);

    public synchronized void setSampleValue(int i, int j, double d)
    {
        chartData.setSampleValue(i, j, d);
        hasChanged = true;
        if(isValueLabelsOn(i) && getLabelAngle("valueLabelAngle") != 0)
            angledLabelCache.clear();
        autoRepaint();
    }

    public synchronized double getSampleValue(int i, int j)
    {
        return chartData.getSampleValue(i, j);
    }

    public synchronized int appendSampleValue(int i, double d, boolean flag)
    {
        int j = chartData.appendSampleValue(i, d, flag);
        hasChanged = true;
        if(isValueLabelsOn(i) && getLabelAngle("valueLabelAngle") != 0)
            angledLabelCache.clear();
        autoRepaint();
        return j;
    }

    double getLowestValue(int i)
    {
        i = Math.min(rangeOn.length - 1, Math.max(0, i));
        int j = getSeriesCount();
        double d = 0.0D;
        for(int k = 0; k < j; k++)
            if(getSeriesRange(k) == i)
                d = Math.min(getMinValue(k), d);

        for(int l = 0; l < overlayCharts.size(); l++)
        {
            Chart chart = (Chart)overlayCharts.elementAt(l);
            if(chart != null && !chart.chartType.equals("pie"))
            {
                for(int i1 = 0; i1 < chart.getSeriesCount(); i1++)
                    if(chart.getSeriesRange(i1) == i)
                        d = Math.min(chart.getMinValue(i1), d);

            }
        }

        return d;
    }

    public void setPrintAsBitmap(boolean flag)
    {
        printAsBitmap = flag;
    }

    private void paintGridLine(Graphics g, Rectangle rectangle, double d, Color color, String s, Color color1, 
            boolean flag, boolean flag1, int i, int j)
    {
        double d1 = 0.0D;
        if(j == 0)
        {
            i = Math.max(0, Math.min(rangeOn.length - 1, i));
            if(currentUpperRange[i] - currentLowerRange[i] != 0.0D)
                d1 = (d - currentLowerRange[i]) / (currentUpperRange[i] - currentLowerRange[i]);
        } else
        if(j == 1)
        {
            Rectangle rectangle1 = getDataBounds(rectangle);
            double d2;
            double d3;
            if(gridAlignment == 1)
            {
                d2 = ((double)(rectangle.x - rectangle1.x) / (double)rectangle1.width) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
                d3 = ((double)((rectangle.width + rectangle.x) - rectangle1.x) / (double)rectangle1.width) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
            } else
            {
                d2 = ((double)(rectangle.y - rectangle1.y) / (double)rectangle1.height) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
                d3 = ((double)((rectangle.height + rectangle.y) - rectangle1.y) / (double)rectangle1.height) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
            }
            d1 = (d - d2) / (d3 - d2);
        }
        FontMetrics fontmetrics = g.getFontMetrics();
        int k = fontmetrics.getHeight();
        int l = fontmetrics.getDescent();
        int i1 = s == null ? 0 : fontmetrics.stringWidth(s);
        if(gridAlignment == 1 && j == 0 || gridAlignment == 0 && j == 1)
        {
            int j1 = (int)Math.round((double)(rectangle.y + rectangle.height) - d1 * (double)rectangle.height);
            if(j == 1)
                j1 = (int)Math.round((double)rectangle.y + d1 * (double)rectangle.height);
            boolean flag2 = j1 >= rectangle.y && j1 <= rectangle.y + rectangle.height;
            boolean flag3 = j1 - k / 2 > rectangle.y + l / 2;
            flag3 &= j1 + k / 2 < (rectangle.y + rectangle.height) - l / 2;
            flag3 |= j == 1 && j1 > rectangle.y && j1 < rectangle.y + rectangle.height;
            flag3 |= j == 0 && d == 0.0D;
            if(flag2 && (flag3 || flag1) || j == 0 && (d == currentLowerRange[i] || d == currentUpperRange[i]))
            {
                if(flag)
                {
                    g.setColor(color);
                    g.drawLine(rectangle.x + 1, j1, (rectangle.x + rectangle.width) - 1, j1);
                    if(display3dOn)
                        g.drawLine(rectangle.x, j1, rectangle.x - depth3dPoint.x, j1 - depth3dPoint.y);
                }
                if(s != null)
                {
                    int l1 = rectangle.x - (!display3dOn || rangePosition[i] != 0 ? 0 : depth3dPoint.x);
                    j1 -= !display3dOn || rangePosition[i] != 0 ? 0 : depth3dPoint.y;
                    int i2 = 0;
                    g.setColor(color1);
                    if(rangePosition[i] == 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -