2015-11-16 51 views
0

使用TChart,在yAxis上,我的數據範圍是從0到100,000的整數值。如何在TChart上對標籤進行格式化,使得如果當前系列的範圍是10,000-100,000,則它會在圖表上以10k,50k,90,100k等形式讀取。這是針對移動應用程序的,因此這樣做的目的是節省手機上的空間以最大化圖表顯示。在TChart上格式化數據Delphi Seattle FMX

用Delphi西雅圖,FMX,開發的iOS/Android的

回答

2

似乎有多種可能性,這裏是使用GetAxisLabel一種方法。對我來說,關鍵是將標籤樣式設置爲talText。

unit Unit1; 

interface 

uses 
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
    FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMXTee.Engine, 
    FMXTee.Series, FMXTee.Procs, FMXTee.Chart; 

type 
    TForm1 = class(TForm) 
    Chart1: TChart; 
    procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries; 
     ValueIndex: Integer; var LabelText: string); 
    procedure FormCreate(Sender: TObject); 
    private 
    { Private declarations } 
    fSeries: TPointSeries; 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.fmx} 

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries; 
    ValueIndex: Integer; var LabelText: string); 
begin 
    if (fSeries = Series) then 
    begin 
    LabelText := IntToStr(Round(Series.YValue[ValueIndex]/1000)) + 'K'; 
    end; 
end; 

procedure TForm1.FormCreate(Sender: TObject); 
var 
    i: NativeInt; 
begin 
    fSeries := TPointSeries.Create(self); 
    fSeries.ParentChart := Chart1; 
    for i := 1 to 10 do 
    begin 
    fSeries.Add(i * 10000); 
    end; 
    Chart1.Axes.Left.LabelStyle := talText; 
end; 

end.