TeeChart for PHP教程(四):轴控制

    TeeChart for PHP包含100%的PHP源代码。它支持PHP5及更高的版本。它可作为一个调色板组件整合到针对PHP的Delphi编程环境中,从而让其他人在运行时以创建组件的方式来引用。第一个版本提供17种图表类型(2D和3D的多种组合),11个数学函数和一些图表工具组件以扩展功能。

点击下载TeeChart for PHP试用版


    本教程是TeeChart for PHP教程中轴控制这一节。本章节的内容主要分为以下几个部分:

  1. 轴控制 - 关键领域

    增量

    标题和标签

    Ticks

    轴位置

  2. 附加轴

    复制轴

    多个自定义轴


轴控制 - 关键领域

    将Series数据添加到Chart时,会自动设置轴刻度。您可以使用Axis方法在运行时更改默认值。

    自动选择最佳轴刻度范围以适合您的数据,如果关闭自动,缩放部分将激活选项,您可以更改轴值。重要的是,请记住从页面左侧的轴列表中选择要配置的轴。

    将一个系列添加到图表,然后使用以下代码添加一个按钮:

$tChart1->removeAllSeries();
$tChart1->addSeries(new Line());
$tChart1->getSeries(0)->fillSampleValues(40);

    在按钮中运行代码将绘制一个包含40个随机值的Line Series。您现在可以配置轴刻度的最大值和最小值。

$tChart1->getAxes()->getBottom()->setMinMax(0,10);

    您可以将Axis scale Maximum和Minimum设置为自动单独运行。 例如:

$tChart1->getAxes()->getBottom()->setAutomatic(false); $tChart1->getAxes()->getBottom()->setAutomaticMaximum(true); $tChart1->getAxes()->getBottom()->setMinimum(2);

增量

    您可以定制Axis的间隔,设置所需的增量:

$tChart1->getAxes()->getBottom()->setIncrement(20);

日期时间数据

    如果您的数据是日期时间(您可以通过指定XValues或YValues为dateTime,然后将数据设置为系列的DateTime),则图表,轴页面和比例部分将显示日期时间范围。您也可以更改所需的增量。

在这里你可以看到一个散点图示例代码:

getHeader()->setText("Scatter Plot"); $chart->getPanel()->getGradient()->setVisible(false); $chart->getAspect()->setView3D(false); $panel=$chart->getPanel(); $panel->getBevel()->setInner(BevelStyle::$NONE); $panel->getBevel()->setOuter(BevelStyle::$NONE); $panel->getPen()->setColor(new Color(120,120,120)); $panel->getPen()->setVisible(true); $line = new Line($chart->getChart()); // Adding DateTime data $today = gettimeofday(true);  $days7 = 7 * 86400;  $days2 = 2 * 86400;  $end_date = $today + $days7;  $end_task2= $end_date + $days7 ;  $chart->getChart()->getSeries(0)->getXValues()->setDateTime(true);  $chart->getChart()->getAxes()->getBottom()->getLabels()->setAngle(45);  $chart->getChart()->getAxes()->getBottom()->getLabels()->setRoundFirstLabel(false); // If you want to set a datetime format... // $chart->getChart()->getAxes()->getBottom()->getLabels()->setDateTimeFormat('d-m-y h:m:s'); $line->addXY($today,30); $line->addXY($today+86400,32); $line->addXY($today+$days2,20); $line->addXY($end_date+$days7+$days7,8); $line->addXY($end_date+$days7+$days7+$days2,18);  $line->addXY($end_date+$days7+$days7+$days7,10); $line->getLinePen()->setWidth(3); $pointer=$line->getPointer(); $pointer->setVisible(true); $pointer->setStyle(PointerStyle::$CIRCLE); $pointer->getBrush()->setColor(Color::getWhite()); $pointer->getPen()->setColor($line->getColor()); $pointer->getPen()->setWidth(2); $chart->getPanel()->getBorderPen()->setVisible(false); $chart->render("chart1.png"); $rand=rand(); print 'Scatter Plot'; print '';  ?>

    在运行时更改增量:

$tChart1->getAxes()->getBottom()->setIncrement(DateTimeSteps::$ONEWEEK);

    有关日期轴标记的更多信息,请参见Axis-> ExactDateTime属性。

    注意:更改轴标签频率时,请记住TeeChart将根据LabelsSeparation方法的设置避免标签重叠。这意味着如果标签频率太高而没有起到标签的作用,那么TeeChart将分配最佳匹配。更改标签角度和标签分离是2个选项,可帮助您安装所需的标签。这部分请参阅后面的标签部分和LabelsAngle方法。

标题和标签

标题

    标题在Axis页面的标题部分设置,您可以更改Axis及其字体的标题文本,角度可以从值0,90,180,270度中选择。

标签

标签格式

    您可以将所有标准数字和日期格式应用于轴标签。轴页面的标签部分包含值格式字段。如果您的数据是datetime,则字段名称将更改为Date time format。在运行时使用:

$tChart1->getAxes()->getBottom()->getLabels()->setValueFormat("#,##0.00;(#,##0.00)");
//or for Datetime data
$tChart1->getAxes()->getBottom()->getLabels()->setDateTimeFormat("d-m-y h:i:s");

MultiLine标签

    轴标签可以显示为多行文本而不只是单行文本。用TeeLineSeparator全局常量分隔行,该常量默认为回车符ascii字符(#13)。例如:

//Add the Series labels in this way and apply 'Marks' as Axis labelling style
$tChart1->getSeries(0)->addYTextColor(1234, "New cars", Color::BLUE() );
$tChart1->getSeries(0)->addYTextColor(2000, "Old bicycles", Color::GREEN());
$tChart1->getPanel()->setMarginBottom(10);

DateTime标签的示例:

ticks.gif

    有3种刻度类型。您可以更改每种刻度类型的长度,宽度和颜色。如果刻度线宽度设置为1(默认值),则可以将样式更改为多种线型之一(点,短划线等)。如果width大于1,则将忽略样式。

$tChart1->getAxes()->getBottom()->getTicks()->setLength(7);
$tChart1->getAxes()->getBottom()->getTicks()->setColor(Color::GREEN());
$tChart1->getAxes()->getBottom()->setMinorTickCount(10);

轴位置

    轴有一种方法可以修改每个轴的位置,在此示例中,轴会移动到图表总宽度的50%,因此它显示在图表中心:

$tChart1->getAxes()->getLeft()->setRelativePosition(50);

附加轴

复制轴

    TeeChart提供5个轴与数据系列相关联:左,上,下,右和深。向图表添加新系列时,您可以定义系列应与哪些轴相关。

自定义轴

    在此示例中,TeeChart将绘制一个新轴,一个水平,一个垂直位于图表的中心。

多个自定义轴

    与PositionPercent和拉伸属性一起,可以在图表上的任何位置浮动无限轴。现在可以通过几行代码在运行时创建额外的轴:

$tChart1 = new TChart(500,300); $line1 = new Line(); $line2 = new Line(); $tChart1->getAspect()->setView3D(false); $tChart1->getHeader()->setText("TeeChart Multiple Axes"); $tChart1->addSeries($line1); $tChart1->addSeries($line2); for($t = 0; $t addXYColor($t, (10 + $t), Color::RED()); if($t > 1) {  $line2->addXYColor($t, $t, Color::GREEN()); } }  $tChart1->getAxes()->getLeft()->setStartPosition(0); $tChart1->getAxes()->getLeft()->setEndPosition(50); $tChart1->getAxes()->getLeft()->getAxisPen()->color = Color::RED(); $tChart1->getAxes()->getLeft()->getTitle()->getFont()->setColor(Color::RED()); $tChart1->getAxes()->getLeft()->getTitle()->getFont()->setBold(true); $tChart1->getAxes()->getLeft()->getTitle()->setText("1st Left Axis");

    然后,您可以使用StartPosition和EndPosition方法将新轴与图表的整体关系来定位。这些数字表示为图表矩形的百分比,其中0(零)(在垂直轴的情况下)为Top。这些属性可以应用于标准轴,以在图表中创建完全分区的子图表。

$axis1 = new Axis(false, false, $tChart1->getChart()); $tChart1->getAxes()->getCustom()->add($axis1); $line2->setCustomVertAxis($axis1); $axis1->setStartPosition(50); $axis1->setEndPosition(100); $axis1->getAxisPen()->setColor(Color::GREEN()); $axis1->getTitle()->getFont()->setColor(Color::GREEN()); $axis1->getTitle()->getFont()->setBold(true); $axis1->getTitle()->setText("Extra Axis"); $axis1->setRelativePosition(20);

    上面的编码示例将显示以下图表:

多轴

    注意:使用自定义轴时要小心,因为很容易会用新轴填充屏幕并且无法跟踪您想要管理的轴。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值