📄 financechart.php
字号:
<?php
require_once("../lib/phpchartdir.php");
#/////////////////////////////////////////////////////////////////////////////////////////////////
# Copyright 2006 Advanced Software Engineering Limited
#
# ChartDirector FinanceChart class library
# - Requires ChartDirector Ver 4.1 or above
#
# You may use and modify the code in this file in your application, provided the code and
# its modifications are used only in conjunction with ChartDirector. Usage of this software
# is subjected to the terms and condition of the ChartDirector license.
#/////////////////////////////////////////////////////////////////////////////////////////////////
#/ <summary>
#/ Represents a Financial Chart
#/ </summary>
class FinanceChart extends MultiChart
{
var $m_totalWidth = 0;
var $m_totalHeight = 0;
var $m_antiAlias = true;
var $m_logScale = false;
var $m_axisOnRight = true;
var $m_leftMargin = 40;
var $m_rightMargin = 40;
var $m_topMargin = 30;
var $m_bottomMargin = 35;
var $m_plotAreaBgColor = 0xfffff0;
var $m_majorHGridColor = 0xdddddd;
var $m_minorHGridColor = 0xdddddd;
var $m_majorVGridColor = 0xdddddd;
var $m_minorVGridColor = 0xdddddd;
var $m_legendFont = "normal";
var $m_legendFontSize = 8;
var $m_legendFontColor = TextColor;
var $m_legendBgColor = 0x80ccccff;
var $m_yAxisFont = "normal";
var $m_yAxisFontSize = 8;
var $m_yAxisFontColor = TextColor;
var $m_yAxisMargin = 13;
var $m_xAxisFont = "normal";
var $m_xAxisFontSize = 8;
var $m_xAxisFontColor = TextColor;
var $m_xAxisFontAngle = 0;
var $m_timeStamps = null;
var $m_highData = null;
var $m_lowData = null;
var $m_openData = null;
var $m_closeData = null;
var $m_volData = null;
var $m_volUnit = "";
var $m_extraPoints = 0;
var $m_yearFormat = "{value|yyyy}";
var $m_firstMonthFormat = "<*font=bold*>{value|mmm yy}";
var $m_otherMonthFormat = "{value|mmm}";
var $m_firstDayFormat = "<*font=bold*>{value|d mmm}";
var $m_otherDayFormat = "{value|d}";
var $m_firstHourFormat = "<*font=bold*>{value|d mmm\nh:nna}";
var $m_otherHourFormat = "{value|h:nna}";
var $m_timeLabelSpacing = 50;
var $m_generalFormat = "G";
var $m_toolTipMonthFormat = "[{xLabel|mmm yyyy}]";
var $m_toolTipDayFormat = "[{xLabel|mmm d, yyyy}]";
var $m_toolTipHourFormat = "[{xLabel|mmm d, yyyy hh:nn:ss}]";
var $m_mainChart = null;
var $m_currentChart = null;
#/ <summary>
#/ Create a FinanceChart with a given width. The height will be automatically determined
#/ as the chart is built.
#/ </summary>
#/ <param name="width">Width of the chart in pixels</param>
function FinanceChart($width) {
$this->MultiChart($width, 1);
$this->m_totalWidth = $width;
}
#/ <summary>
#/ Enable/Disable anti-alias. Enabling anti-alias makes the line smoother. Disabling
#/ anti-alias make the chart file size smaller, and so can be downloaded faster
#/ through the Internet. The default is to enable anti-alias.
#/ </summary>
#/ <param name="antiAlias">True to enable anti-alias. False to disable anti-alias.</param>
function enableAntiAlias($antiAlias) {
$this->m_antiAlias = $antiAlias;
}
#/ <summary>
#/ Set the margins around the plot area.
#/ </summary>
#/ <param name="m_leftMargin">The distance between the plot area and the chart left edge.</param>
#/ <param name="m_topMargin">The distance between the plot area and the chart top edge.</param>
#/ <param name="m_rightMargin">The distance between the plot area and the chart right edge.</param>
#/ <param name="m_bottomMargin">The distance between the plot area and the chart bottom edge.</param>
function setMargins($leftMargin, $topMargin, $rightMargin, $bottomMargin) {
$this->m_leftMargin = $leftMargin;
$this->m_rightMargin = $rightMargin;
$this->m_topMargin = $topMargin;
$this->m_bottomMargin = $bottomMargin;
}
#/ <summary>
#/ Add a text title above the plot area. You may add multiple title above the plot area by
#/ calling this method multiple times.
#/ </summary>
#/ <param name="alignment">The alignment with respect to the region that is on top of the
#/ plot area.</param>
#/ <param name="text">The text to add.</param>
#/ <returns>The TextBox object representing the text box above the plot area.</returns>
function addPlotAreaTitle($alignment, $text) {
$ret = $this->addText($this->m_leftMargin, 0, $text, "bold", 10, TextColor, $alignment);
$ret->setSize($this->m_totalWidth - $this->m_leftMargin - $this->m_rightMargin + 1,
$this->m_topMargin - 1);
$ret->setMargin(0);
return $ret;
}
#/ <summary>
#/ Set the plot area style. The default is to use pale yellow 0xfffff0 as the background,
#/ and light grey 0xdddddd as the grid lines.
#/ </summary>
#/ <param name="bgColor">The plot area background color.</param>
#/ <param name="majorHGridColor">Major horizontal grid color.</param>
#/ <param name="majorVGridColor">Major vertical grid color.</param>
#/ <param name="minorHGridColor">Minor horizontal grid color. In current version, minor
#/ horizontal grid is not used.</param>
#/ <param name="minorVGridColor">Minor vertical grid color.</param>
function setPlotAreaStyle($bgColor, $majorHGridColor, $majorVGridColor, $minorHGridColor,
$minorVGridColor) {
$this->m_plotAreaBgColor = $bgColor;
$this->m_majorHGridColor = $majorHGridColor;
$this->m_majorVGridColor = $majorVGridColor;
$this->m_minorHGridColor = $minorHGridColor;
$this->m_minorVGridColor = $minorVGridColor;
}
#/ <summary>
#/ Set legend style. The default is Arial 8 pt black color, with light grey background.
#/ </summary>
#/ <param name="font">The font of the legend text.</param>
#/ <param name="fontSize">The font size of the legend text in points.</param>
#/ <param name="fontColor">The color of the legend text.</param>
#/ <param name="bgColor">The background color of the legend box.</param>
function setLegendStyle($font, $fontSize, $fontColor, $bgColor) {
$this->m_legendFont = $font;
$this->m_legendFontSize = $fontSize;
$this->m_legendFontColor = $fontColor;
$this->m_legendBgColor = $bgColor;
}
#/ <summary>
#/ Set x-axis label style. The default is Arial 8 pt black color no rotation.
#/ </summary>
#/ <param name="font">The font of the axis labels.</param>
#/ <param name="fontSize">The font size of the axis labels in points.</param>
#/ <param name="fontColor">The color of the axis labels.</param>
#/ <param name="fontAngle">The rotation of the axis labels.</param>
function setXAxisStyle($font, $fontSize, $fontColor, $fontAngle) {
$this->m_xAxisFont = $font;
$this->m_xAxisFontSize = $fontSize;
$this->m_xAxisFontColor = $fontColor;
$this->m_xAxisFontAngle = $fontAngle;
}
#/ <summary>
#/ Set y-axis label style. The default is Arial 8 pt black color, with 13 pixels margin.
#/ </summary>
#/ <param name="font">The font of the axis labels.</param>
#/ <param name="fontSize">The font size of the axis labels in points.</param>
#/ <param name="fontColor">The color of the axis labels.</param>
#/ <param name="axisMargin">The margin at the top of the y-axis in pixels (to leave
#/ space for the legend box).</param>
function setYAxisStyle($font, $fontSize, $fontColor, $axisMargin) {
$this->m_yAxisFont = $font;
$this->m_yAxisFontSize = $fontSize;
$this->m_yAxisFontColor = $fontColor;
$this->m_yAxisMargin = $axisMargin;
}
#/ <summary>
#/ Set whether the main y-axis is on right of left side of the plot area. The default is
#/ on right.
#/ </summary>
#/ <param name="b">True if the y-axis is on right. False if the y-axis is on left.</param>
function setAxisOnRight($b) {
$this->m_axisOnRight = $b;
}
#/ <summary>
#/ Determines if log scale should be used for the main chart. The default is linear scale.
#/ </summary>
#/ <param name="b">True for using log scale. False for using linear scale.</param>
function setLogScale($b) {
$this->m_logScale = $b;
if ($this->m_mainChart != null) {
if ($this->m_logScale) {
$this->m_mainChart->yAxis->setLogScale();
} else {
$this->m_mainChart->yAxis->setLinearScale();
}
}
}
#/ <summary>
#/ Set the date/time formats to use for the x-axis labels under various cases.
#/ </summary>
#/ <param name="yearFormat">The format for displaying labels on an axis with yearly ticks. The
#/ default is "yyyy".</param>
#/ <param name="firstMonthFormat">The format for displaying labels on an axis with monthly ticks.
#/ This parameter applies to the first available month of a year (usually January) only, so it can
#/ be formatted differently from the other labels.</param>
#/ <param name="otherMonthFormat">The format for displaying labels on an axis with monthly ticks.
#/ This parameter applies to months other than the first available month of a year.</param>
#/ <param name="firstDayFormat">The format for displaying labels on an axis with daily ticks.
#/ This parameter applies to the first available day of a month only, so it can be formatted
#/ differently from the other labels.</param>
#/ <param name="otherDayFormat">The format for displaying labels on an axis with daily ticks.
#/ This parameter applies to days other than the first available day of a month.</param>
#/ <param name="firstHourFormat">The format for displaying labels on an axis with hourly
#/ resolution. This parameter applies to the first tick of a day only, so it can be formatted
#/ differently from the other labels.</param>
#/ <param name="otherHourFormat">The format for displaying labels on an axis with hourly.
#/ resolution. This parameter applies to ticks at hourly boundaries, except the first tick
#/ of a day.</param>
function setDateLabelFormat($yearFormat, $firstMonthFormat, $otherMonthFormat, $firstDayFormat,
$otherDayFormat, $firstHourFormat, $otherHourFormat) {
if ($yearFormat != null) {
$this->m_yearFormat = $yearFormat;
}
if ($firstMonthFormat != null) {
$this->m_firstMonthFormat = $firstMonthFormat;
}
if ($otherMonthFormat != null) {
$this->m_otherMonthFormat = $otherMonthFormat;
}
if ($firstDayFormat != null) {
$this->m_firstDayFormat = $firstDayFormat;
}
if ($otherDayFormat != null) {
$this->m_otherDayFormat = $otherDayFormat;
}
if ($firstHourFormat != null) {
$this->m_firstHourFormat = $firstHourFormat;
}
if ($otherHourFormat != null) {
$this->m_otherHourFormat = $otherHourFormat;
}
}
#/ <summary>
#/ Set the minimum label spacing between two labels on the time axis
#/ </summary>
#/ <param name="labelSpacing">The minimum label spacing in pixels.</param>
function setDateLabelSpacing($labelSpacing) {
if ($labelSpacing > 0) {
$this->m_timeLabelSpacing = $labelSpacing;
} else {
$this->m_timeLabelSpacing = 0;
}
}
#/ <summary>
#/ Set the tool tip formats for display date/time
#/ </summary>
#/ <param name="monthFormat">The tool tip format to use if the data point spacing is one
#/ or more months (more than 30 days).</param>
#/ <param name="dayFormat">The tool tip format to use if the data point spacing is 1 day
#/ to less than 30 days.</param>
#/ <param name="hourFormat">The tool tip format to use if the data point spacing is less
#/ than 1 day.</param>
function setToolTipDateFormat($monthFormat, $dayFormat, $hourFormat) {
if ($monthFormat != null) {
$this->m_toolTipMonthFormat = $monthFormat;
}
if ($dayFormat != null) {
$this->m_toolTipDayFormat = $dayFormat;
}
if ($hourFormat != null) {
$this->m_toolTipHourFormat = $hourFormat;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -