翻譯|使用教程|編輯:況魚杰|2019-07-29 09:58:03.030|閱讀 354 次
概述:TeeChart for PHP將自動為您定義所有軸標簽,并擁有足夠的靈活性來定制您可能的任何特定要求。它提供真正的多軸,具有無數的可能性和軸定義的靈活性,本教程就將會介紹高級軸設計技術。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart for PHP包含100%的PHP源代碼。它支持PHP5及更高的版本。它可作為一個調色板組件整合到針對PHP的Delphi編程環境中,從而讓其他人在運行時以創建組件的方式來引用。第一個版本提供17種圖表類型(2D和3D的多種組合),11個數學函數和一些圖表工具組件以擴展功能。
本教程是TeeChart for PHP教程中軸控制這一節。本章節的內容主要分為以下幾個部分:
軸控制 - 關鍵領域
Scales
增量
標題和標簽
Ticks
軸位置
附加軸
復制軸
多個自定義軸
軸控制 - 關鍵領域
Scales
將Series數據添加到Chart時,會自動設置軸刻度。您可以使用軸方法在運行時更改默認值。
自動選擇最佳軸刻度范圍以適合您的數據,如果關閉自動按鈕,縮放部分將激活選項,您可以更改軸值。重要的是,請記住從頁面左側的軸列表中選擇要配置的軸。
將一個系列添加到圖表,然后使用以下代碼添加一個按鈕:
$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);
增量
您可以定制軸的間隔,設置所需的增量:
$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方法。
標題和標簽
標題
標題在軸頁面的標題部分設置,您可以更改軸及其字體的標題文本,角度可以從值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標簽的示例:
有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);
上面的編碼示例將顯示以下圖表:
注意:使用自定義軸時要小心,因為很容易會用新軸填充屏幕并且無法跟蹤您想要管理的軸。
TeeChart for PHP已加入在線訂購,現在搶購即可享受優惠!
關注慧聚IT微信公眾號???,了解產品的最新動態及最新資訊。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: