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

📄 financechart.php

📁 一个绝对棒的报表绘图软件
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                $delim = ", ";
            }
            $label = "$openLabel$highLabel$lowLabel$closeLabel";

            $useUpColor = ($closeValue >= $openValue);
            if ($candleStickMode != true) {
                $tmpArrayMath1 = new ArrayMath($this->m_closeData);
                $tmpArrayMath1->delta();
                $closeChanges = $tmpArrayMath1->result();
                $lastChangeIndex = $this->lastIndex($closeChanges);
                $useUpColor = ($lastChangeIndex < 0);
                if ($useUpColor != true) {
                    $useUpColor = ($closeChanges[$lastChangeIndex] >= 0);
                }
            }

            $udcolor = $downColor;
            if ($useUpColor) {
                $udcolor = $upColor;
            }
            $legendObj = $this->m_mainChart->getLegend();
            $legendObj->addKey($label, $udcolor);
        }
    }

    #/ <summary>
    #/ Add a closing price line on the main chart.
    #/ </summary>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addCloseLine($color) {
        return $this->addLineIndicator2($this->m_mainChart, $this->m_closeData, $color,
            "Closing Price");
    }

    #/ <summary>
    #/ Add a weight close line on the main chart.
    #/ </summary>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addWeightedClose($color) {
        $tmpArrayMath1 = new ArrayMath($this->m_highData);
        $tmpArrayMath1->add($this->m_lowData);
        $tmpArrayMath1->add($this->m_closeData);
        $tmpArrayMath1->add($this->m_closeData);
        $tmpArrayMath1->div(4);
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color,
            "Weighted Close");
    }

    #/ <summary>
    #/ Add a typical price line on the main chart.
    #/ </summary>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addTypicalPrice($color) {
        $tmpArrayMath1 = new ArrayMath($this->m_highData);
        $tmpArrayMath1->add($this->m_lowData);
        $tmpArrayMath1->add($this->m_closeData);
        $tmpArrayMath1->div(3);
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color,
            "Typical Price");
    }

    #/ <summary>
    #/ Add a median price line on the main chart.
    #/ </summary>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addMedianPrice($color) {
        $tmpArrayMath1 = new ArrayMath($this->m_highData);
        $tmpArrayMath1->add($this->m_lowData);
        $tmpArrayMath1->div(2);
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color,
            "Median Price");
    }

    #/ <summary>
    #/ Add a simple moving average line on the main chart.
    #/ </summary>
    #/ <param name="period">The moving average period</param>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addSimpleMovingAvg($period, $color) {
        $label = "SMA ($period)";
        $tmpArrayMath1 = new ArrayMath($this->m_closeData);
        $tmpArrayMath1->movAvg($period);
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color, $label
            );
    }

    #/ <summary>
    #/ Add an exponential moving average line on the main chart.
    #/ </summary>
    #/ <param name="period">The moving average period</param>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addExpMovingAvg($period, $color) {
        $label = "EMA ($period)";
        $tmpArrayMath1 = new ArrayMath($this->m_closeData);
        $tmpArrayMath1->expAvg(2.0 / ($period + 1));
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color, $label
            );
    }

    #/ <summary>
    #/ Add a triangular moving average line on the main chart.
    #/ </summary>
    #/ <param name="period">The moving average period</param>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addTriMovingAvg($period, $color) {
        $label = "TMA ($period)";
        $tmpArrayMath1 = new ArrayMath($this->computeTriMovingAvg($this->m_closeData, $period));
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color, $label
            );
    }

    #/ <summary>
    #/ Add a weighted moving average line on the main chart.
    #/ </summary>
    #/ <param name="period">The moving average period</param>
    #/ <param name="color">The color of the line.</param>
    #/ <returns>The LineLayer object representing the line created.</returns>
    function addWeightedMovingAvg($period, $color) {
        $label = "WMA ($period)";
        $tmpArrayMath1 = new ArrayMath($this->computeWeightedMovingAvg($this->m_closeData, $period))
            ;
        return $this->addLineIndicator2($this->m_mainChart, $tmpArrayMath1->result(), $color, $label
            );
    }

    #/ <summary>
    #/ Add a generic band to the main finance chart. This method is used internally by other methods to add
    #/ various bands (eg. Bollinger band, Donchian channels, etc).
    #/ </summary>
    #/ <param name="upperLine">The data series for the upper band line.</param>
    #/ <param name="lowerLine">The data series for the lower band line.</param>
    #/ <param name="lineColor">The color of the upper and lower band line.</param>
    #/ <param name="fillColor">The color to fill the region between the upper and lower band lines.</param>
    #/ <param name="name">The name of the band.</param>
    #/ <returns>An InterLineLayer object representing the filled region.</returns>
    function addBand($upperLine, $lowerLine, $lineColor, $fillColor, $name) {
        $i = count($upperLine) - 1;
        if ($i >= count($lowerLine)) {
            $i = count($lowerLine) - 1;
        }

        while ($i >= 0) {
            if (($upperLine[$i] != NoValue) && ($lowerLine[$i] != NoValue)) {
                $name = sprintf("%s: %s - %s", $name, $this->formatValue($lowerLine[$i],
                    $this->m_generalFormat), $this->formatValue($upperLine[$i],
                    $this->m_generalFormat));
                break;
            }
            $i = $i - 1;
        }

        $uLayer = $this->m_mainChart->addLineLayer($upperLine, $lineColor, $name);
        $lLayer = $this->m_mainChart->addLineLayer($lowerLine, $lineColor);
        return $this->m_mainChart->addInterLineLayer($uLayer->getLine(), $lLayer->getLine(),
            $fillColor);
    }

    #/ <summary>
    #/ Add a Bollinger band on the main chart.
    #/ </summary>
    #/ <param name="period">The period to compute the band.</param>
    #/ <param name="bandWidth">The half-width of the band in terms multiples of standard deviation. Typically 2 is used.</param>
    #/ <param name="lineColor">The color of the lines defining the upper and lower limits.</param>
    #/ <param name="fillColor">The color to fill the regional within the band.</param>
    #/ <returns>The InterLineLayer object representing the band created.</returns>
    function addBollingerBand($period, $bandWidth, $lineColor, $fillColor) {
        #Bollinger Band is moving avg +/- (width * moving std deviation)
        $tmpArrayMath1 = new ArrayMath($this->m_closeData);
        $tmpArrayMath1->movStdDev($period);
        $tmpArrayMath1->mul($bandWidth);
        $stdDev = $tmpArrayMath1->result();
        $tmpArrayMath1 = new ArrayMath($this->m_closeData);
        $tmpArrayMath1->movAvg($period);
        $movAvg = $tmpArrayMath1->result();
        $label = "Bollinger ($period, $bandWidth)";
        $tmpArrayMath1 = new ArrayMath($movAvg);
        $tmpArrayMath1->add($stdDev);
        $tmpArrayMath2 = new ArrayMath($movAvg);
        $tmpArrayMath2->sub($stdDev);
        $tmpArrayMath2->selectGTZ(null, 0);
        return $this->addBand($tmpArrayMath1->result(), $tmpArrayMath2->result(), $lineColor,
            $fillColor, $label);
    }

    #/ <summary>
    #/ Add a Donchian channel on the main chart.
    #/ </summary>
    #/ <param name="period">The period to compute the band.</param>
    #/ <param name="lineColor">The color of the lines defining the upper and lower limits.</param>
    #/ <param name="fillColor">The color to fill the regional within the band.</param>
    #/ <returns>The InterLineLayer object representing the band created.</returns>
    function addDonchianChannel($period, $lineColor, $fillColor) {
        #Donchian Channel is the zone between the moving max and moving min
        $label = "Donchian ($period)";
        $tmpArrayMath1 = new ArrayMath($this->m_highData);
        $tmpArrayMath1->movMax($period);
        $tmpArrayMath2 = new ArrayMath($this->m_lowData);
        $tmpArrayMath2->movMin($period);
        return $this->addBand($tmpArrayMath1->result(), $tmpArrayMath2->result(), $lineColor,
            $fillColor, $label);
    }

    #/ <summary>
    #/ Add a price envelop on the main chart. The price envelop is a defined as a ratio around a
    #/ moving average. For example, a ratio of 0.2 means 20% above and below the moving average.
    #/ </summary>
    #/ <param name="period">The period for the moving average.</param>
    #/ <param name="range">The ratio above and below the moving average.</param>
    #/ <param name="lineColor">The color of the lines defining the upper and lower limits.</param>
    #/ <param name="fillColor">The color to fill the regional within the band.</param>
    #/ <returns>The InterLineLayer object representing the band created.</returns>
    function addEnvelop($period, $range, $lineColor, $fillColor) {
        #Envelop is moving avg +/- percentage
        $tmpArrayMath1 = new ArrayMath($this->m_closeData);
        $tmpArrayMath1->movAvg($period);
        $movAvg = $tmpArrayMath1->result();
        $label = sprintf("Envelop (SMA %s +/- %s%%)", $period, (int)($range * 100));
        $tmpArrayMath1 = new ArrayMath($movAvg);
        $tmpArrayMath1->mul(1 + $range);
        $tmpArrayMath2 = new ArrayMath($movAvg);
        $tmpArrayMath2->mul(1 - $range);
        return $this->addBand($tmpArrayMath1->result(), $tmpArrayMath2->result(), $lineColor,
            $fillColor, $label);
    }

    #/ <summary>
    #/ Add a volume bar chart layer on the main chart.
    #/ </summary>
    #/ <param name="height">The height of the bar chart layer in pixels.</param>
    #/ <param name="upColor">The color to used on an 'up' day. An 'up' day is a day where
    #/ the closing price is higher than that of the previous day.</param>
    #/ <param name="downColor">The color to used on a 'down' day. A 'down' day is a day
    #/ where the closing price is lower than that of the previous day.</param>
    #/ <param name="flatColor">The color to used on a 'flat' day. A 'flat' day is a day
    #/ where the closing price is the same as that of the previous day.</param>
    #/ <returns>The XYChart object representing the chart created.</returns>
    function addVolBars($height, $upColor, $downColor, $flatColor) {
        return $this->addVolBars2($this->m_mainChart, $height, $upColor, $downColor, $flatColor);
    }

    function addVolBars2(&$c, $height, $upColor, $downColor, $flatColor) {
        #Compute an array to represent the closing price changes
        $tmpArrayMath1 = new ArrayMath($this->m_closeData);
        $tmpArrayMath1->delta();
        $closeChange = $tmpArrayMath1->result();

        $tmpArrayMath1 = new ArrayMath($this->m_volData);
        $tmpArrayMath1->selectGTZ($closeChange);
        $upLayer = $this->addBarIndicator2($c, $tmpArrayMath1->result(), $upColor, "");
        $tmpArrayMath1 = new ArrayMath($this->m_volData);
        $tmpArrayMath1->selectLTZ($closeChange);
        $dnLayer = $this->addBarIndicator2($c, $tmpArrayMath1->result(), $downColor, "");
        $tmpArrayMath1 = new ArrayMath($this->m_volData);
        $tmpArrayMath1->selectEQZ($closeChange);
        $flatLayer = $this->addBarIndicator2($c, $tmpArrayMath1->result(), $flatColor, "");

        $tmpArrayMath1 = new ArrayMath($this->m_volData);
        $maxVol = $tmpArrayMath1->max();
        if ($c == $this->m_mainChart) {
            $this->configureYAxis($c->yAxis2(), $height);
            $drawAreaObj = $c->getDrawArea();
            $topMargin = $drawAreaObj->getHeight() - $this->m_topMargin - $this->m_bottomMargin -
                $height + $this->m_yAxisMargin;
            if ($topMargin < 0) {
                $topMargin = 0;
            }
            $c->yAxis2->setTopMargin($topMargin);
            $upLayer->setUseYAxis2();
            $dnLayer->setUseYAxis2();
            $flatLayer->setUseYAxis2();
        }

        $a = $c->yAxis2;
        if ($c != $this->m_mainChart) {
            $a = $c->yAxis;
        }
        $volFormat = "";
        if ($maxVol < 10) {
            $volFormat = sprintf("{value|1}%s", $this->m_volUnit);
        } else {
            $volFormat = sprintf("{value}%s", $this->m_volUnit);
        }
        $a->setLabelFormat($volFormat);

⌨️ 快捷键说明

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