📄 jvqchart.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
JvChart - TJvChart Component
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvChart.PAS, released on 2003-09-30.
The Initial Developers of the Original Code are
Warren Postma (TJvChart which was originally based on TAABGraph)
M錼ten Henrichson (TAABGraph)
Contributor(s):
Warren Postma (warrenpstma att hotmail dott com)
M錼ten Henrichson/AABSoft (no email known)
Contains some code which is
(C) 1996-1998 AABsoft and M錼ten Henrichson
The rest is
(C) 2003 Warren Postma
warren.postma att sympatico dott ca
warrenpstma att hotmail dott com
Last Modified:
2003-09-30 - (WP) - Alpha-Initial checkin of new component, into JVCL3 CVS tree.
2004-02-26 - (WP) - Pre-JVCL3.0-Has been substantially jedified, also new
properties/events, and some renaming has occurred. See
cvs logs. NEW: OnChartClick event.
RENAME: Options.ThickLineWidth -> Options.PenLineWidth
RENAME: Values -> ValueIndex
2004-04-10 - (WP) - Much improved Charting! Beta-Quality in most places.
Significant property reorganization and renaming.
Primary and Secondary Y (vertical) Axis support.
2004-07-06 - (WP)- Added events OnYAxisClick (Left margin click),
OnXAxisClick (Bottom margin), OnAltYAxisClick (Right margin)
and OnTitleClick (Top Margin).
2005-01-14 - (WP) - Floating Chart Markers added. Major changes to painting
code to allow canvas as a parameter. This is in preparation
for fixing up the printing code to allow printing to work
once again, and because the floating objects require us to
draw the chart into a bitmap, and then decorate the bitmap
dynamically with the floating objects, different
canvases are used to paint the bitmap, and to paint the
floating layer on top, thus the need for the changes.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
MARCH 2004 -JVCL3BETA- STILL IN DEVELOPMENT. REPORT PROBLEMS TO JEDI JVCL
BUG TRACKING SYSTEM (AKA 'MANTIS') AND THE JEDI.VCL NEWSGROUP!
JUNE 23 2004 -JVCL3BETA- Negative values and anything other than 0 in
YMin properties was causing problems. Fixed. -WPostma.
-----------------------------------------------------------------------------}
// $Id: JvQChart.pas,v 1.36 2005/02/06 14:06:01 asnepvangers Exp $
unit JvQChart;
{$I jvcl.inc}
interface
uses
QWindows, QMessages, Classes, QGraphics, QControls, Contnrs,
JvQComponent;
const
JvChartVersion = 300; // ie, version 3.00
JvDefaultHintColor = TColor($00DDFBFA);
JvDefaultAvgLineColor = TColor($00EEDDDD);
JvDefaultDivisionLineColor = clLtGray; //NEW!
JvDefaultShadowColor = clLtGray; //NEW!
JvDefaultYLegends = 20;
MaxShowXValueInLegends = 10;
// Special indices to GetPenColor(Index)
jvChartAverageLineColorIndex = -6;
jvChartDivisionLineColorIndex = -5;
jvChartShadowColorIndex = -4;
jvChartAxisColorIndex = -3;
jvChartHintColorIndex = -2;
jvChartPaperColorIndex = -1;
JvChartDefaultMarkerSize = 3;
type
{ CHART TYPES }
TJvChartKind =
(ckChartNone, // Blank graph.
ckChartLine, // default type. Line and Marker plots.
ckChartBar,
ckChartStackedBar,
ckChartBarAverage,
ckChartStackedBarAverage,
ckChartPieChart,
//ckChartLineWithMarkers, // obsolete. use ckChartLine, and set PenMarkerKind to cmDiamond.
ckChartMarkers,
ckChartDeltaAverage);
// ckChartLine can have a different pen type for each pen:
TJvChartPenMarkerKind = (pmkNone, pmkDiamond, pmkCircle, pmkSquare, pmkCross);
TJvChartLegend = (clChartLegendNone, clChartLegendRight, clChartLegendBelow);
TJvChartDataArray = array of array of Double;
TJvChart = class;
TJvChartFloatingMarker = class(TObject)
private
FOwner: TJvChart; // Which chart does it belongs to?
protected
FRawXPosition: Integer; // raw pixel-based X position.
FRawYPosition: Integer; // raw pixel-based Y position.
FDragging: Boolean; // drag in progress!
FVisible: Boolean; // Make chart marker object visible or invisible.
FIndex: Integer; // Which marker is this?
FMarker: TJvChartPenMarkerKind; // What symbol to plot at this position?
FMarkerColor: TColor; // Marker color.
FXPosition: Integer; // Plot at same X co-ordinates as Data Sample X.
FYPosition: Double; // Plot at Y height as data
FXDraggable: Boolean; // Can marker be dragged horizontally?
FXDragMin: Integer; // Minimum X Position that we can drag to.
FXDragMax: Integer; // Maximum X Position that we can drag to.
FYDraggable: Boolean; // Can marker be dragged vertically?
//FYPositionToPen:Integer; // YPosition copied from Pen Values. (-1=disable feature, 0=first pen,1=second pen,...)
FLineToMarker: Integer; // If -1 then none. Otherwise, index of another marker object
FLineVertical: Boolean; // If true, then this object plots a vertical divider line.
FLineStyle: TPenStyle; // Line style (solid,dashed,etc)
FLineColor: TColor; // Line color.
FLineWidth: Integer;
FCaption: string; // Caption to print above the marker, or if no marker, then just this text is plotted.
//FCaptionBorderStyle:TPenStyle; // Style of border around caption, or psClear if no border.
//FCaptionBorderColor:TColor; //
//PROTECTED CONSTRUCTOR: Only TJvChart should create a new marker object:
constructor Create(Owner: TJvChart);
procedure SetCaption(aCaption: string);
procedure SetXPosition(xPos: Integer); // should invalidate the chart (FOwner) if changed.
procedure SetYPosition(yPos: Double); // should invalidate the chart (FOwner) if changed.
procedure SetVisible(isVisible: Boolean);
public
property Index: Integer read FIndex;
published
property Marker: TJvChartPenMarkerKind read FMarker write FMarker;
property MarkerColor: TColor read FMarkerColor write FMarkerColor; // Marker color.
property Visible: Boolean read FVisible write FVisible; // Make chart marker object visible or invisible.
property XPosition: Integer read FXPosition write SetXPosition;
property YPosition: Double read FYPosition write SetYPosition;
property XDraggable: Boolean read FXDraggable write FXDraggable;
property XDragMin: Integer read FXDragMin write FXDragMin;
property XDragMax: Integer read FXDragMax write FXDragMax;
property YDraggable: Boolean read FYDraggable write FYDraggable;
//property YPositionToPen :Integer read FYPositionToPen write FYPositionToPen;
property LineToMarker: Integer read FLineToMarker write FLineToMarker;
property LineVertical: Boolean read FLineVertical write FLineVertical;
property LineStyle: TPenStyle read FLineStyle write FLineStyle;
property LineColor: TColor read FLineColor write FLineColor;
property LineWidth: Integer read FLineWidth write FLineWidth;
property Caption: string read FCaption write FCaption;
//property CaptionBorderStyle :TPenStyle read FCaptionBorderStyle write FCaptionBorderStyle;
//property CaptionBorderColor :TColor read FCaptionBorderColor write FCaptionBorderColor;
end;
{ TJvChartData : Holds NxN array of Reals, Resizes automatically within preset
limits. Provides a functionality mix of dynamic memory use, but with
a memory cap, so we don't thrash the system or leak forever. -WAP.}
TJvChartData = class(TObject)
private
FData: TJvChartDataArray;
FClearToValue: Double; // Typically either 0.0 or NaN
FTimeStamp: array of TDateTime; // Time-series as a TDateTime
// Dynamic array of dynamic array of Double.
// is empty until data is stored in them.
// *** Order of indexing: FData[ValueIndex,Pen] ***
FDataAlloc: Integer; // Last Allocated Value.
FValueCount: Integer; // Number of sample indices used
protected
procedure Grow(Pen, ValueIndex: Integer);
//GetValue/SetValue resizer, also throws exception if Pen,ValueIndex is negative or just way too big.
function GetValue(Pen, ValueIndex: Integer): Double;
procedure SetValue(Pen, ValueIndex: Integer; NewValue: Double);
function GetTimestamp(ValueIndex: Integer): TDateTime;
procedure SetTimestamp(ValueIndex: Integer; AValue: TDateTime);
public
constructor Create;
destructor Destroy; override;
function DebugStr(ValueIndex: Integer): string; // dump all pens for particular valueindex, as string.
procedure Clear; // Resets All Data to zero.
procedure ClearPenValues; // Clears all pen values to NaN but does not reset pen definitions etc.
procedure Scroll;
property Value[Pen, ValueIndex: Integer]: Double read GetValue write SetValue; default;
property Timestamp[ValueIndex: Integer]: TDateTime read GetTimestamp write SetTimestamp;
property ValueCount: Integer read FValueCount write FValueCount;
property ClearToValue: Double read FClearToValue write FClearToValue; // Typically either 0.0 or NaN. default 0.0
end;
TJvChartPaintEvent = procedure(Sender: TJvChart; ACanvas: TCanvas) of object;
TJvChartEvent = procedure(Sender: TJvChart) of object;
TJvChartFloatingMarkerDragEvent = procedure(Sender: TJvChart; FloatingMarker: TJvChartFloatingMarker) of object; {NEW}
TJvChartClickEvent = procedure(Sender: TJvChart;
Button: TMouseButton; { left/right mouse click?}
Shift: TShiftState; { keyboard shift state?}
X, Y: Integer; { mouse position}
ChartValueIndex: Integer; { what value in the chart? }
ChartPenIndex: Integer; { what pen was clicked? }
{ User modifiable return values for custom hinting! }
var ShowHint, HintFirstLineBold: Boolean; HintStrs: TStrings) of object; {NEW}
TJvChartOptions = class;
{ There are TWO Y Axis per graph, optionally:
Chart.Options.PenAxis[I] -and-
Chart.Options.SecondaryYAxisOne
The primary one is displayed along the left side, and the one
for the right side is only displayed if you need it.
Properties for each side are grouped by the
TJvChartYAxisOptions persistent-properties-object.
}
TJvChartYAxisOptions = class(TPersistent)
private
FOwner: TJvChartOptions;
FActive: Boolean; // One or more pens use this Y Axis.
protected
FYMax: Double; // Y Scale value at the top left hand side of chart.
FYMin: Double; // Y Scale value at the bottom left hand side of the chart (default 0)
FYGap: Double; // Number of values per Y scale division
FYGap1: Double; // Gap multiplication factor for value scaling.
FMarkerValueDecimals: Integer; // Decimal places on marker-values (only applies to Marker Pens with Values)
FYDivisions: Integer; // Number of vertical divisions in the chart. (default 10)
FMaxYDivisions: Integer;
FMinYDivisions: Integer;
FYLegendDecimalPlaces: Integer;
FYLegends: TStringList;
FDefaultYLegends: Integer; // Number of default Y legends.
FYPixelGap: Double;
procedure SetYMax(NewYMax: Double);
procedure SetYMin(NewYMin: Double);
// procedure SetYGap(newYgap: Double);
function GetYLegends: TStrings;
procedure SetYLegends(Value: TStrings);
procedure SetYDivisions(AValue: Integer);
public
constructor Create(Owner: TJvChartOptions); virtual;
destructor Destroy; override;
procedure Normalize;
procedure Clear;
// runtime only properties
property YPixelGap: Double read FYPixelGap write FYPixelGap;
property Active: Boolean read FActive;
property YGap: Double read FYGap;
property YGap1: Double read FYGap1; // Gap multiplication factor for value scaling.
property YLegends: TStrings read GetYLegends write SetYLegends; { Y Axis Legends as Strings }
published
property YMax: Double read FYMax write SetYMax;
property YMin: Double read FYMin write SetYMin;
property YDivisions: Integer read FYDivisions write SetYDivisions default 10;
// Number of vertical divisions in the chart
// YDivisions->YDivisions
property MaxYDivisions: Integer read FMaxYDivisions write FMaxYDivisions default 20;
property MinYDivisions: Integer read FMinYDivisions write FMinYDivisions default 5;
property MarkerValueDecimals: Integer read FMarkerValueDecimals write FMarkerValueDecimals default -1;
// Decimal places on marker-values (only applies to Marker Pens with Values)
property YLegendDecimalPlaces: Integer read FYLegendDecimalPlaces write FYLegendDecimalPlaces;
property DefaultYLegends: Integer read FDefaultYLegends write FDefaultYLegends default JvDefaultYLegends;
end;
TJvChartOptions = class(TPersistent)
private
FOwner: TJvChart;
{accessors}
function GetAverageValue(Index: Integer): Double;
procedure SetAverageValue(Index: Integer; AValue: Double);
function GetPenColor(Index: Integer): TColor;
procedure SetPenColor(Index: Integer; AColor: TColor);
function GetPenStyle(Index: Integer): TPenStyle;
procedure SetPenStyle(Index: Integer; APenStyle: TPenStyle);
function GetPenMarkerKind(Index: Integer): TJvChartPenMarkerKind;
procedure SetPenMarkerKind(Index: Integer; AMarkKind: TJvChartPenMarkerKind);
procedure SetXStartOffset(Offset: Integer);
function GetPenSecondaryAxisFlag(Index: Integer): Boolean;
procedure SetPenSecondaryAxisFlag(Index: Integer; NewValue: Boolean);
function GetPenValueLabels(Index: Integer): Boolean;
procedure SetPenValueLabels(Index: Integer; NewValue: Boolean);
procedure SetPenCount(Count: Integer);
procedure SetChartKind(AKind: TJvChartKind);
// TStrings<->TStringList transmogrifiers
function GetPenLegends: TStrings;
procedure SetPenLegends(Value: TStrings);
function GetPenUnit: TStrings;
procedure SetPenUnit(Value: TStrings);
function GetXLegends: TStrings;
procedure SetXLegends(Value: TStrings);
procedure SetHeaderFont(AFont: TFont);
procedure SetLegendFont(AFont: TFont);
procedure SetAxisFont(AFont: TFont);
procedure SetPaperColor(AColor: TColor);
procedure SetPrimaryYAxis(AssignFrom: TJvChartYAxisOptions);
procedure SetSecondaryYAxis(AssignFrom: TJvChartYAxisOptions);
// Each pen can be associated with either the primary or secondary axis,
// this function decides which axis to return depending on the pen configuration:
function GetPenAxis(Index: Integer): TJvChartYAxisOptions;
protected
FChartKind: TJvChartKind; // default JvChartLine
{runtime pixel spacing multipliers}
FXPixelGap: Double;
{Fonts}
FHeaderFont: TFont;
FLegendFont: TFont;
FAxisFont: TFont;
FTitle: string;
FNoDataMessage: string;
FYAxisHeader: string;
FYAxisDivisionMarkers: Boolean; // Do you want grid-paper look?
FXAxisDivisionMarkers: Boolean; // Do you want grid-paper look?
FXAxisHeader: string;
FXLegends: TStringList; // Text labels.
FXLegendMaxTextWidth: Integer; // runtime: display width (pixels) of widest string in FXLegends[1:X].
FXAxisValuesPerDivision: Integer;
// Number of Values (aka samples) in each vertical dotted lines that are divisision marker.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -