⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqchartdemofm.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{******************************************************************************}
{* WARNING:  JEDI VCL To CLX Converter generated unit.                        *}
{*           Manual modifications will be lost on next release.               *}
{******************************************************************************}

{-----------------------------------------------------------------------------
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: JvChartDemoFm.Pas, released on 2002-10-04.

The Initial Developer of the Original Code is AABsoft and M錼ten Henrichson.
(C) 1996 AABsoft and M錼ten Henrichson.
All Rights Reserved.

Contributor(s): -

Last Modified: 2004-01-07
  Modified 2003 Warren Postma

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Description:
  BAR/LINE Charting Component for JEDI

Known Issues:
-----------------------------------------------------------------------------}

unit JvQChartDemoFm;

interface

uses
  QWindows, SysUtils, QMessages, Classes, QGraphics, QControls,
  QForms, QDialogs, QExtCtrls, QStdCtrls, QButtons, QExtDlgs,
  JvQChart, JvQComponent, JvQExControls, StatsClasses, QMenus, QTypes;

type
  TJvChartDemoForm = class(TForm)
    PanelTop: TPanel;
    ButtonBarChart: TSpeedButton;
    ButtonLine: TSpeedButton;
    ButtonStackedBarAve: TSpeedButton;
    ButtonStackedBar: TSpeedButton;
    ButtonBarAve: TSpeedButton;
    ColorDialog1: TColorDialog;
    ButtonPie: TSpeedButton;
    FontDialog1: TFontDialog;
    ButtonMarkers: TSpeedButton;
    ButtonDeltaAverage: TSpeedButton;
    ButtonLineMarker: TSpeedButton;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    Demo1: TMenuItem;
    Help1: TMenuItem;
    About1: TMenuItem;
    AboutJVCL301: TMenuItem;
    ShowgapinLineChart1: TMenuItem;
    N1: TMenuItem;
    Print1: TMenuItem;
    Generatenewrandomvalues1: TMenuItem;
    CopyToClipboard1: TMenuItem;
    N2: TMenuItem;
    SetHeaderFont1: TMenuItem;
    Scrolling1: TMenuItem;
    ListBox1: TListBox;
    Splitter1: TSplitter;
    Timer1: TTimer;
    ShowDataInListbox1: TMenuItem;
    N4: TMenuItem;
    LargeDataset576samples1: TMenuItem;
    DateTimeAxisMode: TMenuItem;
    PrintOptions1: TMenuItem;
    MenuSecondaryAxisMode: TMenuItem;
    MenuNegValueTest: TMenuItem;
    Chart: TJvChart;
    PrinterSetupDialog1: TPrinterSetupDialog;
    procedure FormResize(Sender: TObject);
    procedure ButtonLineClick(Sender: TObject);
    procedure ButtonBarChartClick(Sender: TObject);
    procedure ButtonStackedBarAveClick(Sender: TObject);
    procedure ButtonStackedBarClick(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure ButtonBarAveClick(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ButtonPieClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure ButtonMarkersClick(Sender: TObject);
    procedure ButtonDeltaAverageClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ButtonLineMarkerClick(Sender: TObject);
    procedure Panel2DblClick(Sender: TObject);
    procedure ShowgapinLineChart1Click(Sender: TObject);
    procedure Print1Click(Sender: TObject);
    procedure Generatenewrandomvalues1Click(Sender: TObject);
    procedure CopyToClipboard1Click(Sender: TObject);
    procedure SetHeaderFont1Click(Sender: TObject);
    procedure About1Click(Sender: TObject);
    procedure AboutJVCL301Click(Sender: TObject);
    procedure Scrolling1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ShowDataInListbox1Click(Sender: TObject);
    procedure LargeDataset576samples1Click(Sender: TObject);
    procedure DateTimeAxisModeClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PrintOptions1Click(Sender: TObject);
    procedure MenuSecondaryAxisModeClick(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure MenuNegValueTestClick(Sender: TObject);
  private

      // Our waveform generator uses the following as state-variables:
    FGenerationIndex: Integer;
    Foo, Foo1, Foo2: Integer;
    Fhgt, Fhg0, Fhg2p: Double;
    FStatHgt, FStatHg0: TStatArray;
    Fdt, Fds: Double;
    FNegValueFlag: Boolean;

  protected
    procedure _Generate;
    procedure _StoreValue(I: integer);
    function _QAProblemScatter: Integer;

  public
    procedure NewValues;
  end;

var
  JvChartDemoForm: TJvChartDemoForm;

implementation

uses
  JvQJVCLAboutForm, // JVCL About box stuff.
//  ShellApi ; // ShellApi:ShellExecute function
  Math; // Math:NaN handling, function isNan in D6 and higher.

{$R *.xfm}

{ Bogus vageuly sinusoidal signal generator }

procedure TJvChartDemoForm._Generate;
begin
  FHgt := Abs(Random(80) + (Random(((FGenerationIndex div foo) mod foo1) * 250) * 5 + 9500));
  FHg0 := Abs(Random(280) + Random(((FGenerationIndex div foo) mod foo2) * 650) * 5 + 1003);
  if FNegValueFlag then
  begin
    if (Random(80) > 75) or (FGenerationIndex = 2) then
    begin
      FHg0 := -1 * FHg0; // Generate a negative value! (just to show what it looks like)
    end;
  end;
  Inc(FGenerationIndex);
end;

{ Bogus random spiky-looking function to simulate a QA value,
  which hovers within +/- 10% of perfect (100%), but
  with relatively infrequent spiky errors }

function TJvChartDemoForm._QAProblemScatter: Integer;
var
  n, m: Double;
begin
  n := Log10(Random(10000) + 1); // Random is my favourite function. How about you? -WP
  n := n * Log10(Random(10000) + 1);
  m := Log10(Random(10000) + 1);
  m := m * Log10(Random(10000) + 1);
  n := Abs(100 + n - m);
  if (n < 0) then
    n := 0;
  if (n > 150) then
    n := 150;

  Result := Round(n);
end;

procedure TJvChartDemoForm._StoreValue(I: integer);
begin
  FStatHgt.AddValue(Fhgt);
  FStatHg0.AddValue(Fhg0);

    // PAY ATTENTION HERE, this is where we set the Chart.Data.Value[ index,pen] := <values>
    // stuff which is the MOST IMPORTANT THING, unless you like blank charts:

    // Set Data.Value[Pen, Series] := dataValue ...
  Chart.Data.Value[0, I] := FStatHgt.Average / 1000;

  if FHg0 < 0 then
  begin
    Chart.Data.Value[1, I] := FHg0 / 1000;
    // Don't show average with negative samples or my negative demo ability goes away (averaged out!)
  end
  else
  begin
    // Test blanks on big chart, show missing data:
    Chart.Data.Value[1, I] := FStatHg0.Average / 1000;
  end;

  Fhg2p := (FStatHgt.Average - FStatHg0.Average) / 1000;
  if Fhg2p < 0.0 then
    Fhg2p := 0.0;
  Chart.Data.Value[2, I] := Fhg2p;

  Fds := Fdt + (FGenerationIndex / 576);

    // There are TWO ways to get an X Axis label plotted:
  if DateTimeAxisMode.Checked then
    Chart.Data.Timestamp[I] := Fds // X legends generated by timestamps
  else
    // X Legends generated by user are used by default.
    // This would be redundant, and would be a waste of memory
    // if Chart.Options.XAxisDateTimeMode was also set.
    Chart.Options.XLegends.Add(FormatDateTime('hh:nn:ss', Fds));

  if MenuSecondaryAxisMode.Checked then
  begin
    if I = 1 then
      Chart.Data.Value[3, I] := 100
    else
    if (I mod 4) = 3 then
    begin
        //Chart.Data.Value[3,I] :=  1+ ((I mod 12) * 10) // stairstep
        //random:
      Chart.Data.Value[3, I] := _QAProblemScatter;
    end
    else
      Chart.Data.Value[3, I] := NaN; // leave some blanks.
  end;
end;

procedure TJvChartDemoForm.NewValues;
var
  I: Integer;
  nValueCount: Integer;
begin
  ListBox1.Clear;
  Chart.Data.Clear;

  Randomize;

  Chart.Options.XAxisDateTimeMode := DateTimeAxisMode.Checked; // Use datetime timestamp labels, just Fer Instance.

  if not Chart.Options.XAxisDateTimeMode then
    Chart.Options.XAxisLegendSkipBy := 5;

  if LargeDataset576samples1.Checked then
  begin
     // A larger bogus data set for demonstration purposes.
    nValueCount := 576; // 2.5 minute sample period, 576 samples = 1 day.
    foo := 5; // Used in generating our bogus data below, not really important.
    Chart.Options.XAxisValuesPerDivision := 24;
      // 24 samples * 150 seconds = 1 hour time divisions (     Chart.Options.XAxisValuesPerDivision := 4;
  end
  else
  begin
     // A smaller bogus data set for demonstration purposes.
    nValueCount := 24; // 2.5 minute sample period, 24 samples =1 hour.
    foo := 1; // Used in generating our bogus data below, not really important.
    Chart.Options.XAxisValuesPerDivision := 4; // five divisions, 4 values per division
  end;

  //Chart.ResetGraphModule;    // Clears YMax.
  Fdt := Trunc(now - 1.0); // yesterday, midnight.
  Foo1 := Random(5) + 2; // more randomness
  Foo2 := Random(3) + 5; // more randomness
  FGenerationIndex := 1;
  for I := 0 to nValueCount - 1 do
  begin
    if i > 0 then
    begin // generate random data that appears to show a sawtooth-frequency-pattern plus a lot of random noise:
      _Generate;
    end
    else
    begin
      Fhgt := 7000; // First sample always known value, helps me troubleshoot.
      Fhg0 := 1000;
    end;

    _StoreValue(I);

    // Override stored value in special cases:

    { How to make a gap in the data! }
    if (nValueCount > 100) and ShowgapinLineChart1.Checked then
    begin
      if (I > 100) and (I < 130) then
      begin
        Chart.Data.Value[0, I] := NaN; // Use special Math.NaN const
        Chart.Data.Value[1, I] := NaN; // Use special Math.NaN const
        Chart.Data.Value[2, I] := NaN; // Use special Math.NaN const
      end;
    end;

    // Just so that the last two values are visibly different, to make sure
    // the chart handles the final vaulues correctly, we set all the final
    // values to known amounts also:
    if I = nValueCount - 2 then
    begin
      Chart.Data.Value[0, I] := 6.0; // Use special Math.NaN const
      Chart.Data.Value[1, I] := 4.0; // Use special Math.NaN const
      Chart.Data.Value[2, I] := 2.0; // Use special Math.NaN const
    end
    else
    if I = nValueCount - 1 then
    begin
      Chart.Data.Value[0, I] := 3.0; // Use special Math.NaN const
      Chart.Data.Value[1, I] := 2.0; // Use special Math.NaN const

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -