📄 jvqchart.pas
字号:
FXAxisLegendSkipBy: Integer; //1=print every X axis label, 2=every other, and so on. default=1
FXLegendHoriz: Integer; // Horizontally oriented GraphXAxisLegend ends at this X Point.
FXAxisDateTimeMode: Boolean; // False=use custom text labels, True=Use Date/Time Stamps as X axis labels.
FXAxisDateTimeFormat: string; // Usually a short date-time label, hh:nn:ss is good.
FDateTimeFormat: string;
// Usually a long date-time label, ISO standard yyyy-mm-dd hh:nn:ss is fine, as is Windows locale defaults.
FXValueCount: Integer;
// Number of pens:
FPenCount: Integer;
// Per-pen array/list properties
FPenColors: array of TColor;
FPenStyles: array of TPenStyle; // solid, dotted
FPenMarkerKind: array of TJvChartPenMarkerKind;
FPenSecondaryAxisFlag: array of Boolean; // False=Primary Y Axis, True=Secondary Y Axis.
FPenValueLabels: array of Boolean;
FPenLegends: TStringList;
FPenUnit: TStringList;
FAverageValue: array of Double; // Used in averaging chart types only.
FPrimaryYAxis: TJvChartYAxisOptions;
FSecondaryYAxis: TJvChartYAxisOptions;
FXGap: Double; // Number of pixels per X scale unit.
FXOrigin: Integer; {which value corresponds to Origin}
FYOrigin: Integer; // Vertical (Y) Position of the Origin point, and X axis.
FXStartOffset: Longint; {margin} // Horizontal (X) Position of the Origin point, and Y Axis
FYStartOffset: Longint; // height of the top margin above the charting area.
FXEnd: Longint; { From top left of control, add XEnd to find where the right margin starts }
FYEnd: Longint; { from top left of control, add YEnd to find where the below-the bottom margin starts }
FMarkerSize: Integer; { marker size. previously called PointSize which sounded like a Font attribute. }
{ more design time }
FLegendWidth: Integer;
FLegendRowCount: Integer; // Number of lines of text in legend.
FAutoUpdateGraph: Boolean;
FMouseEdit: Boolean;
FMouseDragObjects: Boolean; // Can mouse drag floating objects?
FMouseInfo: Boolean;
FLegend: TJvChartLegend; // was FShowLegend, now Legend=clChartLegendRight
FPenLineWidth: Integer;
FAxisLineWidth: Integer;
//COLORS:
FPaperColor: TColor;
FDivisionLineColor: TColor; // NEW! Division line
FShadowColor: TColor; // NEW! Shadow color
FAxisLineColor: TColor; // Color of box around chart plot area.
FHintColor: TColor; // Hint box color
FAverageLineColor: TColor; // Pen color for Charts with auto-average lines.
FCursorColor: TColor; // Sample indicator Cursor color
FCursorStyle: TPenStyle; // Cursor style.
{ event interface }
procedure NotifyOptionsChange;
public
constructor Create(Owner: TJvChart); virtual;
destructor Destroy; override;
{ runtime properties }
property AverageValue[Index: Integer]: Double read GetAverageValue write SetAverageValue;
property PenAxis[Index: Integer]: TJvChartYAxisOptions read GetPenAxis;
property XLegends: TStrings read GetXLegends write SetXLegends; { X Axis Legends as Strings }
{ plot-canvas size, depends on size of control }
property XEnd: Longint read FXEnd write FXEnd;
property YEnd: Longint read FYEnd write FYEnd;
{ pixel spacing : multipliers to scale real values into X/Y pixel amounts before plotting. CRITICALLY important. }
property XPixelGap: Double read FXPixelGap write FXPixelGap;
property XLegendMaxTextWidth: Integer read FXLegendMaxTextWidth write FXLegendMaxTextWidth;
{ Per Pen Array/List Properties -- settable at RUNTIME only. }
property PenColor[Index: Integer]: TColor read GetPenColor write SetPenColor;
property PenStyle[Index: Integer]: TPenStyle read GetPenStyle write SetPenStyle;
property PenMarkerKind[Index: Integer]: TJvChartPenMarkerKind read GetPenMarkerKind write SetPenMarkerKind;
property PenSecondaryAxisFlag[Index: Integer]: Boolean read GetPenSecondaryAxisFlag write SetPenSecondaryAxisFlag;
property PenValueLabels[Index: Integer]: Boolean read GetPenValueLabels write SetPenValueLabels;
published
{ design time}
{ Per Pen Array/List Properties - settable at DESIGNTIME. Others (color/style, marker) are runtime only. }
property PenLegends: TStrings read GetPenLegends write SetPenLegends;
property PenUnit: TStrings read GetPenUnit write SetPenUnit;
property ChartKind: TJvChartKind read FChartKind write SetChartKind default ckChartLine;
property Title: string read FTitle write FTitle;
property NoDataMessage: string read FNoDataMessage write FNoDataMessage;
//NEW! NOV 2004. Optionally display this instead of fixed resource string rsNoData
{ X Axis Properties }
property YAxisHeader: string read FYAxisHeader write FYAxisHeader;
property YAxisDivisionMarkers: Boolean read FYAxisDivisionMarkers write FYAxisDivisionMarkers default True;
// Do you want grid-paper look?
{ X Axis Properties }
property XAxisDivisionMarkers: Boolean read FXAxisDivisionMarkers write FXAxisDivisionMarkers default True;
// Do you want grid-paper look?
property XAxisValuesPerDivision: Integer read FXAxisValuesPerDivision write FXAxisValuesPerDivision;
// Number of Values (aka samples) in each vertical dotted lines that are divisision marker.
property XAxisDateTimeMode: Boolean read FXAxisDateTimeMode write FXAxisDateTimeMode;
property XAxisDateTimeFormat: string read FXAxisDateTimeFormat write FXAxisDateTimeFormat;
property XAxisHeader: string read FXAxisHeader write FXAxisHeader;
property XAxisLegendSkipBy: Integer read FXAxisLegendSkipBy write FXAxisLegendSkipBy default 1;
property DateTimeFormat: string read FDateTimeFormat write FDateTimeFormat;
// Usually a long date-time label, ISO standard yyyy-mm-dd hh:nn:ss is fine, as is Windows locale defaults.
property PenCount: Integer read FPenCount write SetPenCount default 1;
property XGap: Double read FXGap write FXGap;
property XOrigin: Integer read FXOrigin write FXOrigin;
property YOrigin: Integer read FYOrigin write FYOrigin; // Position of bottom of chart (not always the zero origin)
property XStartOffset: Longint read FXStartOffset write SetXStartOffset default 45;
property YStartOffset: Longint read FYStartOffset write FYStartOffset default 10;
{ Y Range }
{ plotting markers }
property MarkerSize: Integer read FMarkerSize write FMarkerSize default JvChartDefaultMarkerSize;
{ !! New: Primary (left side) Y axis, and Secondary (right side) Y Axis !!}
property PrimaryYAxis: TJvChartYAxisOptions read FPrimaryYAxis write SetPrimaryYAxis;
property SecondaryYAxis: TJvChartYAxisOptions read FSecondaryYAxis write SetSecondaryYAxis;
//1=print every X axis label, 2=every other, and so on. default=1
{ vertical numeric decimal places }
{ more design time }
property AutoUpdateGraph: Boolean read FAutoUpdateGraph write FAutoUpdateGraph default True;
property MouseEdit: Boolean read FMouseEdit write FMouseEdit default True;
property MouseDragObjects: Boolean read FMouseDragObjects write FMouseDragObjects;
// Can mouse drag floating objects?
property MouseInfo: Boolean read FMouseInfo write FMouseInfo default True;
//OLD:property ShowLegend: Boolean read FShowLegend write FShowLegend default True;
//CHANGEDTO:
property Legend: TJvChartLegend read FLegend write FLegend default clChartLegendNone;
property LegendRowCount: Integer read FLegendRowCount write FLegendRowCount;
property LegendWidth: Integer read FLegendWidth write FLegendWidth default 150;
property PenLineWidth: Integer read FPenLineWidth write FPenLineWidth default 1;
property AxisLineWidth: Integer read FAxisLineWidth write FAxisLineWidth default 2;
{ more and more design time. these ones not sure about whether they are designtime or not.}
property XValueCount: Integer read FXValueCount write FXValueCount default 10;
{Font properties}
property HeaderFont: TFont read FHeaderFont write SetHeaderFont;
property LegendFont: TFont read FLegendFont write SetLegendFont;
property AxisFont: TFont read FAxisFont write SetAxisFont;
{ Color properties}
property DivisionLineColor: TColor read FDivisionLineColor write FDivisionLineColor default
JvDefaultDivisionLineColor; // NEW! Division line
property ShadowColor: TColor read FShadowColor write FShadowColor default JvDefaultShadowColor; // NEW! Shadow color
property PaperColor: TColor read FPaperColor write SetPaperColor;
property AxisLineColor: TColor read FAxisLineColor write FAxisLineColor;
property HintColor: TColor read FHintColor write FHintColor default JvDefaultHintColor;
property AverageLineColor: TColor read FAverageLineColor write FAverageLineColor default JvDefaultAvgLineColor;
property CursorColor: TColor read FCursorColor write FCursorColor;
property CursorStyle: TPenStyle read FCursorStyle write FCursorStyle;
end;
TJvChart = class(TJvGraphicControl)
private
FUpdating: Boolean; // PREVENT ENDLESS EVENT LOOPING.
FAutoPlotDone: Boolean; // If Options.AutoUpdateGraph is set, then has paint method called PlotGraph already?
FPlotGraphCalled: Boolean; // Has bitmap ever been painted?
FInPlotGraph: Boolean; // recursion blocker.
// NEW: The component has always had a feature when you click on margin areas
// that the user can enter a value (Y Axis Scale, title, and X header)
// The right margin however didn't do anything. Now all four have a user
// event that can be fired. If you don't want the default editor behaviours
// turn off Options.MouseEdit to make it 100% user-defined what happens when
// the user clicks on an area of the chart.
FOnYAxisClick: TJvChartEvent; // Left margin (Primary Y Axis labels) click
FOnXAxisClick: TJvChartEvent; // Bottom margin (X Axis Header) click
FOnAltYAxisClick: TJvChartEvent; // Right margin click (Secondary Y Axis labels)
FOnTitleClick: TJvChartEvent; // Title area click (Top margin)
FOnChartClick: TJvChartClickEvent; // mouse click event
FOnBeginFloatingMarkerDrag: TJvChartFloatingMarkerDragEvent;
FOnEndFloatingMarkerDrag: TJvChartFloatingMarkerDragEvent;
// low level mouse and paint events intended ONLY FOR ADVANCED USERS:
FOnChartPaint: TJvChartPaintEvent;
// After chart bitmap is painted onto control surface we can "decorate" it with owner-drawn extras.
FMouseDownShowHint: Boolean; // True=showing hint.
FMouseDownHintBold: Boolean; // True=first line of hint is bold.
FMouseDownHintStrs: TStringList;
{ TImage stuff}
FPicture: TPicture; // An image drawn via GDI primitives, saveable as
// bitmap or WMF, or displayable to screen
FData: TJvChartData;
FDragFloatingMarker: TJvChartFloatingMarker; //Current object we are dragging ( nil=none )
FFloatingMarker: TObjectList; // NEW: collection of TJvChartFloatingMarker objects.
FAverageData: TJvChartData;
FBitmap: TBitmap;
FOptions: TJvChartOptions; //^TOptions;
//Options2 : ^TOptions2; // now FData
PrintInSession: Boolean;
FStartDrag: Boolean;
FMouseLegend: Boolean;
FContainsNegative: Boolean;
{ strColorFile: string;}// not used (ahuser)
FOldYOrigin: Integer;
FOldYGap: Double;
FMouseDownX: Longint;
FMouseDownY: Longint;
FMouseValue: Integer;
FMousePen: Integer;
FYFont: TFont; // Delphi Font object wrapper.
//NEW:
FXOrigin: Double; {was in TJvChart.PlotGraph}
FYOrigin: Double; {was in TJvChart.PlotGraph}
//FYTempOrigin: Integer; {was in TJvChart.PlotGraph}
FXAxisPosition: Integer; // how far down (in Y dimension) is the X axis?
FOnOptionsChangeEvent: TJvChartEvent; { Component fires this event for when options change.}
FOnPaint: TJvChartPaintEvent; {NEW JAN 2005: Custom paint event called from TjvChart.Paint.}
FCursorPosition: Integer; // NEW: -1 means no visible cursor, 0..n means make
// particular value highlighted. The highlight is painted
// over top of the TImage, so that we can just restore the TImage
// without replotting the whole chart.
procedure PaintCursor; // called from Paint iif a Cursor is visible. does NOT modify FPicture!
protected
procedure DrawFloatingMarkers;
function GetFloatingMarker(Index: Integer): TJvChartFloatingMarker;
{ Right Side Legend showing Pen Names, and/or Data Descriptors }
procedure GraphXAxisLegendMarker(ACanvas: TCanvas; MarkerKind: TJvChartPenMarkerKind; X, Y: Integer);
procedure GraphXAxisLegend;
procedure MyHeader(ACanvas: TCanvas; StrText: string);
procedure MyXHeader(ACanvas: TCanvas; StrText: string);
procedure MyYHeader(ACanvas: TCanvas; StrText: string); // NEW
procedure MyHeaderFont(ACanvas: TCanvas);
procedure MyAxisFont(ACanvas: TCanvas);
procedure MySmallGraphFont(ACanvas: TCanvas);
function MyTextHeight(ACanvas: TCanvas; StrText: string): Longint;
{ TEXTOUT stuff }
procedure MyRightTextOut(ACanvas: TCanvas; X, Y: Integer; const Text: string); // RIGHT TEXT
procedure MyCenterTextOut(ACanvas: TCanvas; X, Y: Integer; const Text: string); // CENTER TEXT
procedure MyLeftTextOut(ACanvas: TCanvas; X, Y: Integer; const Text: string); // LEFT ALIGN TEXT
// Use HintColor:
procedure MyLeftTextOutHint(ACanvas: TCanvas; X, Y: Integer; const Text: string);
{ line, curve, rectangle stuff }
procedure MyPenLineTo(ACanvas: TCanvas; X, Y: Integer);
procedure MyAxisLineTo(ACanvas: TCanvas; X, Y: Integer);
procedure MyRectangle(ACanvas: TCanvas; X, Y, X2, Y2: Integer);
procedure MyColorRectangle(ACanvas: TCanvas; Pen: Integer; X, Y, X2, Y2: Integer);
procedure MyPie(ACanvas: TCanvas; X1, Y1, X2, Y2, X3, Y3, X4, Y4: Longint); { pie chart segment }
// procedure MyArc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer); { arc } // not used (ahuser)
// procedure MyEllipse(X1, Y1, X2, Y2: Integer); // not used (ahuser)
procedure MyDrawLine(ACanvas: TCanvas; X1, Y1, X2, Y2: Integer); // not used (ahuser)
procedure MyDrawAxisMark(ACanvas: TCanvas; X1, Y1, X2, Y2: Integer); // solid line as a tick on an axis.
procedure MyDrawDotLine(ACanvas: TCanvas; X1, Y1, X2, Y2: Integer);
procedure EditXHeader;
procedure EditYScale;
procedure EditHeader;
procedure SetSolidLines(ACanvas: TCanvas);
procedure SetDotLines(ACanvas: TCanvas);
procedure SetLineColor(ACanvas: TCanvas; Pen: Integer);
procedure SetRectangleColor(ACanvas: TCanvas; Pen: Integer);
procedure SetFontColor(ACanvas: TCanvas; Pen: Integer);
procedure CountGraphAverage;
procedure DrawPenColorBox(ACanvas: TCanvas; NColor, W, H, X, Y: Integer);
{ function GetDefaultColorString(nIndex: Integer): string;}// (rom) not used
procedure MyPiePercentage(X1, Y1, W: Longint; NPercentage: Double);
procedure GraphPieChart(NPen: Integer);
procedure GraphDeltaAverage;
procedure MyPieLegend(NPen: Integer);
procedure ShowMouseMessage(X, Y: Integer);
// marker symbols:
procedure MyPolygon(ACanvas: TCanvas; Points: array of TPoint);
procedure PlotCross(ACanvas: TCanvas; X, Y: Integer);
procedure PlotDiamond(ACanvas: TCanvas; X, Y: Integer);
procedure PlotFilledDiamond(ACanvas: TCanvas; X, Y: Integer);
procedure PlotCircle(ACanvas: TCanvas; X, Y: Integer);
procedure PlotSquare(ACanvas: TCanvas; X, Y: Integer);
procedure PlotMarker(ACanvas: TCanvas; MarkerKind: TJvChartPenMarkerKind; X, Y: Integer);
// Calls one of the Plot<Shape> functions.
function MyPt(AX, AY: Integer): TPoint;
procedure ClearScreen;
// internal graphics methods
procedure GraphSetup; // These set up variables used for all the rest of the plotting functions
procedure GraphXAxis;
procedure GraphYAxis;
procedure GraphYAxisDivisionMarkers;
procedure GraphXAxisDivisionMarkers; // new.
procedure CalcYEnd; // Determine where the below-the bottom axis area starts
function GetChartCanvas: TCanvas; // Get Picture.Bitmap Canvas.
function DestRect: TRect; // from TImage
procedure DesignModePaint; // Invoked by Paint method when we're in design mode.
procedure Paint; override; // from TImage
procedure Resize; override; // from TControl
procedure Loaded; override;
{ draw dummy data for design mode}
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure PrimaryYAxisLabels; // Put contents into Options.PrimaryYAxis.YLegends
procedure NotifyOptionsChange; {NEW}
{ internal drawing properties, valid during Paint method invocations only }
property XOrigin: Double read FXOrigin; {was in TJvChart.PlotGraph}
property YOrigin: Double read FYOrigin; {was in TJvChart.PlotGraph}
//property YOldOrigin: Integer read FYOldOrigin; {was in TJvChart.PlotGraph}
//property YTempOrigin: Integer read FYTempOrigin; {was in TJvChart.PlotGraph}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// Get the X and Y Value for a particular Mouse location:
function MouseToXValue(X: Integer): Integer;
// convert X pixel mouse position to data index, ie Data.Values[..,<INDEX>].
function MouseToYValue(Y: Integer): Double;
// convert Y pixel mouse position to value in range Options.PrimaryYAxis.Min to Options.PrimaryYAxis.mAx
{General procedures for the graph...}
procedure ResetGraphModule; {Call this before totally new values and Pen}
//procedure AutoFormatGraph; {XXX BAD CODE. TO BE DELETED. MAY BE REPLACED LATER BY NEW AutoRange FUNCTION!}
procedure PlotGraph; {Update screen / draw graph to screen}
procedure PrintGraph; {Send picture to printer; all printing done by component}
procedure AddGraphToOpenPrintCanvas(XStartPos, YStartPos, GraphWidth, GraphHeight: Longint);
{adds the graph to the "OPEN" printer canvas}
{printing control=outside this component; add other text etc}
procedure GraphToClipboard; {Puts picture on clipboard}
procedure ResizeChartCanvas; {Call this after screen resize and after start up}
procedure PivotData; { Pivot Table. Switches the x values with Pen! Resets AverageLine}
procedure AutoHint; // Make the automatic hint message showing all pens and their values.
procedure SetCursorPosition(Pos: Integer);
// FLOATING MARKERS: NEW JAN 2005. -WP
function AddFloatingMarker: TJvChartFloatingMarker; // NEW Jan 2005!
procedure DeleteFloatingMarker(Index: Integer); // NEW Jan 2005!
procedure ClearFloatingMarkers;
property FloatingMarker[Index: Integer]: TJvChartFloatingMarker read GetFloatingMarker; // NEW Jan 2005!
property Data: TJvChartData read FData;
property AverageData: TJvChartData read FAverageData;
public
{runtime only helper properties}
{ TImage-like stuff }
property Picture: TPicture read FPicture; // write SetPicture;
// NEW: Ability to highlight a particular sample by setting the Cursor position!
property CursorPosition: Integer read FCursorPosition write SetCursorPosition;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -