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

📄 financedemochart.php

📁 一个绝对棒的报表绘图软件
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    }

    # In some finance chart presentation style, even if the data for the latest day
    # is not fully available, the axis for the entire day will still be drawn, where
    # no data will appear near the end of the axis.
    if ($resolution < 86400) {
        # Add extra points to the axis until it reaches the end of the day. The end
        # of day is assumed to be 16:00 (it depends on the stock exchange).
        $lastTime = $timeStamps[count($timeStamps) - 1];
        $extraTrailingPoints = (int)((16 * 3600 - fmod2($lastTime, 86400)) /
            $resolution);
        for($i = 0; $i < $extraTrailingPoints; ++$i) {
            $timeStamps[] = $lastTime + $resolution * ($i + 1);
        }
    }

    #
    # At this stage, all data is available. We can draw the chart as according to
    # user input.
    #

    #
    # Determine the chart size. In this demo, user can select 4 different chart
    # sizes. Default is the large chart size.
    #
    $width = 780;
    $mainHeight = 250;
    $indicatorHeight = 80;

    $chartSize = $_REQUEST["ChartSize"];
    if ($chartSize == "S") {
        # Small chart size
        $width = 450;
        $mainHeight = 160;
        $indicatorHeight = 60;
    } else if ($chartSize == "M") {
        # Medium chart size
        $width = 620;
        $mainHeight = 210;
        $indicatorHeight = 65;
    } else if ($chartSize == "H") {
        # Huge chart size
        $width = 1000;
        $mainHeight = 320;
        $indicatorHeight = 90;
    }

    # Create the chart object using the selected size
    $m = new FinanceChart($width);

    # Set the data into the chart object
    $m->setData($timeStamps, $highData, $lowData, $openData, $closeData, $volData,
        $extraPoints);

    #
    # We configure the title of the chart. In this demo chart design, we put the
    # company name as the top line of the title with left alignment.
    #
    $m->addPlotAreaTitle(TopLeft, "Random Data $tickerKey");

    # We displays the current date as well as the data resolution on the next line.
    $resolutionText = "";
    if ($resolution == 30 * 86400) {
        $resolutionText = "Monthly";
    } else if ($resolution == 7 * 86400) {
        $resolutionText = "Weekly";
    } else if ($resolution == 86400) {
        $resolutionText = "Daily";
    } else if ($resolution == 900) {
        $resolutionText = "15-min";
    }

    $m->addPlotAreaTitle(BottomLeft, sprintf(
        "<*font=arial.ttf,size=8*>%s - %s chart", $m->formatValue(chartTime2(time()),
        "mmm dd, yyyy"), $resolutionText));

    # A copyright message at the bottom left corner the title area
    $m->addPlotAreaTitle(BottomRight,
        "<*font=arial.ttf,size=8*>(c) Advanced Software Engineering");

    #
    # Set the grid style according to user preference. In this simple demo user
    # interface, user can enable/disable grid lines. The code achieve this by setting
    # the grid color to dddddd (light grey) or Transparent. The plot area background
    # color is set to fffff0 (pale yellow).
    #
    $vGridColor = Transparent;
    if ($_REQUEST["VGrid"] == "1") {
        $vGridColor = 0xdddddd;
    }
    $hGridColor = Transparent;
    if ($_REQUEST["HGrid"] == "1") {
        $hGridColor = 0xdddddd;
    }
    $m->setPlotAreaStyle(0xfffff0, $hGridColor, $vGridColor, $hGridColor, $vGridColor
        );

    #
    # Set log or linear scale according to user preference
    #
    if ($_REQUEST["LogScale"] == "1") {
        $m->setLogScale(true);
    } else {
        $m->setLogScale(false);
    }

    #
    # Add the first techical indicator according. In this demo, we draw the first
    # indicator on top of the main chart.
    #
    addIndicator($m, $_REQUEST["Indicator1"], $indicatorHeight);

    #
    # Add the main chart
    #
    $m->addMainChart($mainHeight);

    #
    # Draw the main chart depending on the chart type the user has selected
    #
    $chartType = $_REQUEST["ChartType"];
    if ($chartType == "Close") {
        $m->addCloseLine(0x000040);
    } else if ($chartType == "TP") {
        $m->addTypicalPrice(0x000040);
    } else if ($chartType == "WC") {
        $m->addWeightedClose(0x000040);
    } else if ($chartType == "Median") {
        $m->addMedianPrice(0x000040);
    }

    #
    # Add moving average lines.
    #
    addMovingAvg($m, $_REQUEST["avgType1"], $avgPeriod1, 0x663300);
    addMovingAvg($m, $_REQUEST["avgType2"], $avgPeriod2, 0x9900ff);

    #
    # Draw the main chart if the user has selected CandleStick or OHLC. We draw it
    # here to make sure it is drawn behind the moving average lines (that is, the
    # moving average lines stay on top.)
    #
    if ($chartType == "CandleStick") {
        $m->addCandleStick(0x33ff33, 0xff3333);
    } else if ($chartType == "OHLC") {
        $m->addHLOC(0x008800, 0xcc0000);
    }

    #
    # Add price band/channel/envelop to the chart according to user selection
    #
    $band = $_REQUEST["Band"];
    if ($band == "BB") {
        $m->addBollingerBand(20, 2, 0x9999ff, 0xc06666ff);
    } else if ($band == "DC") {
        $m->addDonchianChannel(20, 0x9999ff, 0xc06666ff);
    } else if ($band == "Envelop") {
        $m->addEnvelop(20, 0.1, 0x9999ff, 0xc06666ff);
    }

    #
    # Add volume bars to the main chart if necessary
    #
    if ($_REQUEST["Volume"] == "1") {
        $m->addVolBars($indicatorHeight, 0x99ff99, 0xff9999, 0xc0c0c0);
    }

    #
    # Add additional indicators as according to user selection.
    #
    addIndicator($m, $_REQUEST["Indicator2"], $indicatorHeight);
    addIndicator($m, $_REQUEST["Indicator3"], $indicatorHeight);
    addIndicator($m, $_REQUEST["Indicator4"], $indicatorHeight);

    return $m;
}


#/ <summary>
#/ Add a moving average line to the FinanceChart object.
#/ </summary>
#/ <param name="m">The FinanceChart object to add the line to.</param>
#/ <param name="avgType">The moving average type (SMA/EMA/TMA/WMA).</param>
#/ <param name="avgPeriod">The moving average period.</param>
#/ <param name="color">The color of the line.</param>
function addMovingAvg(&$m, $avgType, $avgPeriod, $color) {
    if ($avgPeriod > 1) {
        if ($avgType == "SMA") {
            $m->addSimpleMovingAvg($avgPeriod, $color);
        } else if ($avgType == "EMA") {
            $m->addExpMovingAvg($avgPeriod, $color);
        } else if ($avgType == "TMA") {
            $m->addTriMovingAvg($avgPeriod, $color);
        } else if ($avgType == "WMA") {
            $m->addWeightedMovingAvg($avgPeriod, $color);
        }
    }
}


#/ <summary>
#/ Add an indicator chart to the FinanceChart object. In this demo example, the
#/ indicator parameters (such as the period used to compute RSI, colors of the lines,
#/ etc.) are hard coded to commonly used values. You are welcome to design a more
#/ complex user interface to allow users to set the parameters.
#/ </summary>
#/ <param name="m">The FinanceChart object to add the line to.</param>
#/ <param name="indicator">The selected indicator.</param>
#/ <param name="height">Height of the chart in pixels</param>
function addIndicator(&$m, $indicator, $height) {
    if ($indicator == "RSI") {
        $m->addRSI($height, 14, 0x800080, 20, 0xff6666, 0x6666ff);
    } else if ($indicator == "StochRSI") {
        $m->addStochRSI($height, 14, 0x800080, 30, 0xff6666, 0x6666ff);
    } else if ($indicator == "MACD") {
        $m->addMACD($height, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000);
    } else if ($indicator == "FStoch") {
        $m->addFastStochastic($height, 14, 3, 0x006060, 0x606000);
    } else if ($indicator == "SStoch") {
        $m->addSlowStochastic($height, 14, 3, 0x006060, 0x606000);
    } else if ($indicator == "ATR") {
        $m->addATR($height, 14, 0x808080, 0x0000ff);
    } else if ($indicator == "ADX") {
        $m->addADX($height, 14, 0x008000, 0x800000, 0x000080);
    } else if ($indicator == "DCW") {
        $m->addDonchianWidth($height, 20, 0x0000ff);
    } else if ($indicator == "BBW") {
        $m->addBollingerWidth($height, 20, 2, 0x0000ff);
    } else if ($indicator == "DPO") {
        $m->addDPO($height, 20, 0x0000ff);
    } else if ($indicator == "PVT") {
        $m->addPVT($height, 0x0000ff);
    } else if ($indicator == "Momentum") {
        $m->addMomentum($height, 12, 0x0000ff);
    } else if ($indicator == "Performance") {
        $m->addPerformance($height, 0x0000ff);
    } else if ($indicator == "ROC") {
        $m->addROC($height, 12, 0x0000ff);
    } else if ($indicator == "OBV") {
        $m->addOBV($height, 0x0000ff);
    } else if ($indicator == "AccDist") {
        $m->addAccDist($height, 0x0000ff);
    } else if ($indicator == "CLV") {
        $m->addCLV($height, 0x0000ff);
    } else if ($indicator == "WilliamR") {
        $m->addWilliamR($height, 14, 0x800080, 30, 0xff6666, 0x6666ff);
    } else if ($indicator == "Aroon") {
        $m->addAroon($height, 14, 0x339933, 0x333399);
    } else if ($indicator == "AroonOsc") {
        $m->addAroonOsc($height, 14, 0x0000ff);
    } else if ($indicator == "CCI") {
        $m->addCCI($height, 20, 0x800080, 100, 0xff6666, 0x6666ff);
    } else if ($indicator == "EMV") {
        $m->addEaseOfMovement($height, 9, 0x006060, 0x606000);
    } else if ($indicator == "MDX") {
        $m->addMassIndex($height, 0x800080, 0xff6666, 0x6666ff);
    } else if ($indicator == "CVolatility") {
        $m->addChaikinVolatility($height, 10, 10, 0x0000ff);
    } else if ($indicator == "COscillator") {
        $m->addChaikinOscillator($height, 0x0000ff);
    } else if ($indicator == "CMF") {
        $m->addChaikinMoneyFlow($height, 21, 0x008000);
    } else if ($indicator == "NVI") {
        $m->addNVI($height, 255, 0x0000ff, 0x883333);
    } else if ($indicator == "PVI") {
        $m->addPVI($height, 255, 0x0000ff, 0x883333);
    } else if ($indicator == "MFI") {
        $m->addMFI($height, 14, 0x800080, 30, 0xff6666, 0x6666ff);
    } else if ($indicator == "PVO") {
        $m->addPVO($height, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000);
    } else if ($indicator == "PPO") {
        $m->addPPO($height, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000);
    } else if ($indicator == "UO") {
        $m->addUltimateOscillator($height, 7, 14, 28, 0x800080, 20, 0xff6666,
            0x6666ff);
    } else if ($indicator == "Vol") {
        $m->addVolIndicator($height, 0x99ff99, 0xff9999, 0xc0c0c0);
    } else if ($indicator == "TRIX") {
        $m->addTRIX($height, 12, 0x0000ff);
    }
}

# create the finance chart
$c = drawChart();

# output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

⌨️ 快捷键说明

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