searchcode logo

my-chuanqi /vendor/jvcl/examples/JvChartDemo/JvChartDemoFm.pas

svn checkout http://my-chuanqi.googlecode.com/svn/trunk/

Language

Pascal

MD5 Hash

7c6e5467f091bd8c54b1417b8504c2eb

Lines in File 814
Blank Lines 145 (17.81%)
Comment Lines 89 (11%)
Code Lines 579 (71%)
Estimated Development Effort (Months)1.49
Estimated Development Effort (Years)0
Estimated Developers0.51
Estimated Cost$16799.00
Generated using David A. Wheeler's 'SLOCCount'.
  1. {-----------------------------------------------------------------------------
  2. The contents of this file are subject to the Mozilla Public License
  3. Version 1.1 (the "License"); you may not use this file except in compliance
  4. with the License. You may obtain a copy of the License at
  5. http://www.mozilla.org/MPL/MPL-1.1.html
  6.  
  7. Software distributed under the License is distributed on an "AS IS" basis,
  8. WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
  9. the specific language governing rights and limitations under the License.
  10.  
  11. The Original Code is: JvChartDemoFm.Pas, released on 2002-10-04.
  12.  
  13. The Initial Developer of the Original Code is AABsoft and M?rten Henrichson.
  14. (C) 1996 AABsoft and M?rten Henrichson.
  15. All Rights Reserved.
  16.  
  17. Contributor(s): -
  18.  
  19. Last Modified: 2005-01-14
  20.  
  21.   Modified March 2007 by Warren Postma - Show new JvChart 2007 Features.
  22.  
  23.  
  24. You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
  25. located at http://jvcl.sourceforge.net
  26.  
  27. Description:
  28.   BAR/LINE Charting Component for JEDI [Updated March 2007]
  29.  
  30. Known Issues:
  31. -----------------------------------------------------------------------------}
  32.  
  33. unit JvChartDemoFm;
  34.  
  35. interface
  36.  
  37. uses
  38. Windows, SysUtils, Messages, Classes, Graphics, Controls,
  39. Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Spin,
  40. JvChart, JvComponent, JvExControls, StatsClasses, Menus;
  41.  
  42. type
  43. TJvChartDemoForm = class(TForm)
  44. PanelTop: TPanel;
  45. ButtonBarChart: TSpeedButton;
  46. ButtonLine: TSpeedButton;
  47. ButtonStackedBarAve: TSpeedButton;
  48. ButtonStackedBar: TSpeedButton;
  49. ButtonBarAve: TSpeedButton;
  50. ColorDialog1: TColorDialog;
  51. ButtonPie: TSpeedButton;
  52. FontDialog1: TFontDialog;
  53. ButtonMarkers: TSpeedButton;
  54. ButtonDeltaAverage: TSpeedButton;
  55. Chart: TJvChart;
  56. ButtonLineMarker: TSpeedButton;
  57. Label1: TLabel;
  58. MainMenu1: TMainMenu;
  59. Demo1: TMenuItem;
  60. Help1: TMenuItem;
  61. About1: TMenuItem;
  62. AboutJVCL301: TMenuItem;
  63. ShowgapinLineChart1: TMenuItem;
  64. N1: TMenuItem;
  65. Print1: TMenuItem;
  66. Generatenewrandomvalues1: TMenuItem;
  67. CopyToClipboard1: TMenuItem;
  68. N2: TMenuItem;
  69. SetHeaderFont1: TMenuItem;
  70. Scrolling1: TMenuItem;
  71. ListBox1: TListBox;
  72. Splitter1: TSplitter;
  73. Timer1: TTimer;
  74. ShowDataInListbox1: TMenuItem;
  75. N4: TMenuItem;
  76. LargeDataset576samples1: TMenuItem;
  77. DateTimeAxisMode: TMenuItem;
  78. PrintOptions1: TMenuItem;
  79. PrinterSetupDialog1: TPrinterSetupDialog;
  80. PrintDialog1: TPrintDialog;
  81. MenuSecondaryAxisMode: TMenuItem;
  82. MenuNegValueTest: TMenuItem;
  83. SpeedButtonTestMouseOver: TSpeedButton;
  84. NewFeaturesfor20071: TMenuItem;
  85. procedure FormResize(Sender: TObject);
  86. procedure ButtonLineClick(Sender: TObject);
  87. procedure ButtonBarChartClick(Sender: TObject);
  88. procedure ButtonStackedBarAveClick(Sender: TObject);
  89. procedure ButtonStackedBarClick(Sender: TObject);
  90. procedure SpeedButton7Click(Sender: TObject);
  91. procedure ButtonBarAveClick(Sender: TObject);
  92. procedure SpinEdit1Change(Sender: TObject);
  93. procedure Button2Click(Sender: TObject);
  94. procedure ButtonPieClick(Sender: TObject);
  95. procedure Button4Click(Sender: TObject);
  96. procedure ButtonMarkersClick(Sender: TObject);
  97. procedure ButtonDeltaAverageClick(Sender: TObject);
  98. procedure FormCreate(Sender: TObject);
  99. procedure ButtonLineMarkerClick(Sender: TObject);
  100. procedure Panel2DblClick(Sender: TObject);
  101. procedure ShowgapinLineChart1Click(Sender: TObject);
  102. procedure Print1Click(Sender: TObject);
  103. procedure Generatenewrandomvalues1Click(Sender: TObject);
  104. procedure CopyToClipboard1Click(Sender: TObject);
  105. procedure SetHeaderFont1Click(Sender: TObject);
  106. procedure About1Click(Sender: TObject);
  107. procedure AboutJVCL301Click(Sender: TObject);
  108. procedure Scrolling1Click(Sender: TObject);
  109. procedure Timer1Timer(Sender: TObject);
  110. procedure ShowDataInListbox1Click(Sender: TObject);
  111. procedure LargeDataset576samples1Click(Sender: TObject);
  112. procedure DateTimeAxisModeClick(Sender: TObject);
  113. procedure FormDestroy(Sender: TObject);
  114. procedure PrintOptions1Click(Sender: TObject);
  115. procedure MenuSecondaryAxisModeClick(Sender: TObject);
  116. procedure ListBox1DblClick(Sender: TObject);
  117. procedure ListBox1Click(Sender: TObject);
  118. procedure MenuNegValueTestClick(Sender: TObject);
  119. procedure SpeedButtonTestMouseOverClick(Sender: TObject);
  120. procedure ChartEndFloatingMarkerDrag(Sender: TJvChart;
  121. FloatingMarker: TJvChartFloatingMarker);
  122. procedure ChartBeginFloatingMarkerDrag(Sender: TJvChart;
  123. FloatingMarker: TJvChartFloatingMarker);
  124. procedure ChartChartPaint(Sender: TJvChart; aCanvas: TCanvas);
  125. procedure NewFeaturesfor20071Click(Sender: TObject);
  126. private
  127.  
  128. // Our waveform generator uses the following as state-variables:
  129. FGenerationIndex: Integer;
  130. Foo, Foo1, Foo2: Integer;
  131. Fhgt, Fhg0, Fhg2p: Double;
  132. FStatHgt, FStatHg0: TStatArray;
  133. Fdt, Fds: Double;
  134. FNegValueFlag: Boolean;
  135.  
  136. protected
  137. procedure _Generate;
  138. procedure _StoreValue(I: integer);
  139. function _QAProblemScatter: Integer;
  140.  
  141. public
  142. procedure NewValues;
  143. end;
  144.  
  145. var
  146. JvChartDemoForm: TJvChartDemoForm;
  147.  
  148. implementation
  149.  
  150. uses
  151. JvJVCLAboutForm, // JVCL About box stuff.
  152. Math, // Math:NaN handling, function isNan in D6 and higher.
  153. {$IFDEF COMPILER5}
  154. JclMath, // JclMath:function isNan for Delphi 5
  155. {$ENDIF COMPILER5}
  156. ShellApi; // ShellApi:ShellExecute function
  157.  
  158. {$R *.dfm}
  159.  
  160. { Bogus vageuly sinusoidal signal generator }
  161.  
  162. procedure TJvChartDemoForm._Generate;
  163. begin
  164. FHgt := Abs(Random(80) + (Random(((FGenerationIndex div foo) mod foo1) * 250) * 5 + 9500));
  165. FHg0 := Abs(Random(280) + Random(((FGenerationIndex div foo) mod foo2) * 650) * 5 + 1003);
  166. if FNegValueFlag then
  167. begin
  168. if (Random(80) > 75) or (FGenerationIndex = 2) then
  169. begin
  170. FHg0 := -1 * FHg0; // Generate a negative value! (just to show what it looks like)
  171. end;
  172. end;
  173. Inc(FGenerationIndex);
  174. end;
  175.  
  176. { Bogus random spiky-looking function to simulate a QA value,
  177.   which hovers within +/- 10% of perfect (100%), but
  178.   with relatively infrequent spiky errors }
  179.  
  180. function TJvChartDemoForm._QAProblemScatter: Integer;
  181. var
  182. n, m: Double;
  183. begin
  184. n := Log10(Random(10000) + 1); // Random is my favourite function. How about you? -WP
  185. n := n * Log10(Random(10000) + 1);
  186. m := Log10(Random(10000) + 1);
  187. m := m * Log10(Random(10000) + 1);
  188. n := Abs(100 + n - m);
  189. if (n < 0) then
  190. n := 0;
  191. if (n > 150) then
  192. n := 150;
  193.  
  194. Result := Round(n);
  195. end;
  196.  
  197. procedure TJvChartDemoForm._StoreValue(I: integer);
  198. begin
  199. FStatHgt.AddValue(Fhgt);
  200. FStatHg0.AddValue(Fhg0);
  201.  
  202. // PAY ATTENTION HERE, this is where we set the Chart.Data.Value[ index,pen] := <values>
  203. // stuff which is the MOST IMPORTANT THING, unless you like blank charts:
  204.  
  205. // Set Data.Value[Pen, Series] := dataValue ...
  206. Chart.Data.Value[0, I] := FStatHgt.Average / 1000;
  207.  
  208. if FHg0 < 0 then
  209. begin
  210. Chart.Data.Value[1, I] := FHg0 / 1000;
  211. // Don't show average with negative samples or my negative demo ability goes away (averaged out!)
  212. end
  213. else
  214. begin
  215. // Test blanks on big chart, show missing data:
  216. Chart.Data.Value[1, I] := FStatHg0.Average / 1000;
  217. end;
  218.  
  219. Fhg2p := (FStatHgt.Average - FStatHg0.Average) / 1000;
  220. if Fhg2p < 0.0 then
  221. Fhg2p := 0.0;
  222. Chart.Data.Value[2, I] := Fhg2p;
  223.  
  224. Fds := Fdt + (FGenerationIndex / 576);
  225.  
  226. // There are TWO ways to get an X Axis label plotted:
  227. if DateTimeAxisMode.Checked then
  228. Chart.Data.Timestamp[I] := Fds // X legends generated by timestamps
  229. else
  230. // X Legends generated by user are used by default.
  231. // This would be redundant, and would be a waste of memory
  232. // if Chart.Options.XAxisDateTimeMode was also set.
  233. Chart.Options.XLegends.Add(FormatDateTime('hh:nn:ss', Fds));
  234.  
  235. if MenuSecondaryAxisMode.Checked then
  236. begin
  237. if I = 1 then
  238. Chart.Data.Value[3, I] := 100
  239. else
  240. if (I mod 4) = 3 then
  241. begin
  242. //Chart.Data.Value[3,I] := 1+ ((I mod 12) * 10) // stairstep
  243. //random:
  244. Chart.Data.Value[3, I] := _QAProblemScatter;
  245. end
  246. else
  247. Chart.Data.Value[3, I] := NaN; // leave some blanks.
  248. end;
  249. end;
  250.  
  251. procedure TJvChartDemoForm.NewFeaturesfor20071Click(Sender: TObject);
  252. var
  253. vbar:TJvChartVerticalBar;
  254. hbar:TJvChartHorizontalBar;
  255. begin
  256. // Try out new features for 2007:
  257.  
  258. // Gradients.
  259. Chart.Options.GradientColor := $00FDEEDB; // powder blue (baby blue) mostly white.
  260. Chart.Options.GradientDirection :=grDown;
  261.  
  262.  
  263.  
  264. // Vertical Bar.
  265. vbar := Chart.AddVerticalBar;
  266. vbar.Color := $00FDDDC7;
  267. vbar.Visible := true;
  268. vbar.XLeft := 6;
  269. vbar.XRight := 7;
  270.  
  271. // Horizontal Bar.
  272. hbar := Chart.AddHorizontalBar;
  273. hbar.Color := $007CCAC7;
  274. hbar.Visible := true;
  275. hbar.YTop := 3;
  276. hbar.YBottom := 2;
  277.  
  278.  
  279.  
  280.  
  281.  
  282. // Lots of things not shown here are new in 2007:
  283. // Floating Marker Count, Delete a floating marker, etc,
  284. // search for 'NEW 2007' in JvChart.pas for a complete
  285. // look at new things.
  286.  
  287. // last thing, always update graph:
  288. Chart.PlotGraph;
  289. //Chart.Refresh;
  290.  
  291.  
  292. end;
  293.  
  294. procedure TJvChartDemoForm.NewValues;
  295. var
  296. I: Integer;
  297. nValueCount: Integer;
  298. begin
  299. //Chart.Options.Title := 'Click on the Chart Title to change it!';
  300.  
  301. Chart.ClearFloatingMarkers; // remove any previous markers.
  302.  
  303.  
  304. ListBox1.Clear;
  305. Chart.Data.Clear;
  306.  
  307. Chart.Options.PrimaryYAxis.YMax := 20;
  308.  
  309. Randomize;
  310.  
  311. Chart.Options.XAxisDateTimeMode := DateTimeAxisMode.Checked; // Use datetime timestamp labels, just Fer Instance.
  312.  
  313. if not Chart.Options.XAxisDateTimeMode then
  314. Chart.Options.XAxisLegendSkipBy := 5;
  315.  
  316. if LargeDataset576samples1.Checked then
  317. begin
  318. // A larger bogus data set for demonstration purposes.
  319. nValueCount := 576; // 2.5 minute sample period, 576 samples = 1 day.
  320. foo := 5; // Used in generating our bogus data below, not really important.
  321. Chart.Options.XAxisValuesPerDivision := 24;
  322. // 24 samples * 150 seconds = 1 hour time divisions ( Chart.Options.XAxisValuesPerDivision := 4;
  323. end
  324. else
  325. begin
  326. // A smaller bogus data set for demonstration purposes.
  327. nValueCount := 24; // 2.5 minute sample period, 24 samples =1 hour.
  328. foo := 1; // Used in generating our bogus data below, not really important.
  329. Chart.Options.XAxisValuesPerDivision := 4; // five divisions, 4 values per division
  330. end;
  331.  
  332. //Chart.ResetGraphModule; // Clears YMax.
  333. Fdt := Trunc(now - 1.0); // yesterday, midnight.
  334. Foo1 := Random(5) + 2; // more randomness
  335. Foo2 := Random(3) + 5; // more randomness
  336. FGenerationIndex := 1;
  337. for I := 0 to nValueCount - 1 do
  338. begin
  339. if i > 0 then
  340. begin // generate random data that appears to show a sawtooth-frequency-pattern plus a lot of random noise:
  341. _Generate;
  342. end
  343. else
  344. begin
  345. Fhgt := 7000; // First sample always known value, helps me troubleshoot.
  346. Fhg0 := 1000;
  347. end;
  348.  
  349. _StoreValue(I);
  350.  
  351. // Override stored value in special cases:
  352.  
  353. { How to make a gap in the data! }
  354. if (nValueCount > 100) and ShowgapinLineChart1.Checked then
  355. begin
  356. if (I > 100) and (I < 130) then
  357. begin
  358. Chart.Data.Value[0, I] := NaN; // Use special Math.NaN const
  359. Chart.Data.Value[1, I] := NaN; // Use special Math.NaN const
  360. Chart.Data.Value[2, I] := NaN; // Use special Math.NaN const
  361. end;
  362. end;
  363.  
  364. // Just so that the last two values are visibly different, to make sure
  365. // the chart handles the final vaulues correctly, we set all the final
  366. // values to known amounts also:
  367. if I = nValueCount - 2 then
  368. begin
  369. Chart.Data.Value[0, I] := 6.0; // Use special Math.NaN const
  370. Chart.Data.Value[1, I] := 4.0; // Use special Math.NaN const
  371. Chart.Data.Value[2, I] := 2.0; // Use special Math.NaN const
  372. end
  373. else
  374. if I = nValueCount - 1 then
  375. begin
  376. Chart.Data.Value[0, I] := 3.0; // Use special Math.NaN const
  377. Chart.Data.Value[1, I] := 2.0; // Use special Math.NaN const
  378. Chart.Data.Value[2, I] := 1.0; // Use special Math.NaN const
  379.  
  380. end;
  381.  
  382. ListBox1.Items.Append(Chart.Data.DebugStr(I));
  383. end;
  384.  
  385. with Chart.Options do
  386. begin
  387. Title := 'Chart Title';
  388. XAxisHeader := 'Date/Time';
  389. YAxisHeader := 'Readings (ng/m3)';
  390.  
  391. if FNegValueFlag then
  392. begin
  393. PrimaryYAxis.YMin := -20;
  394. PrimaryYAxis.YMax := 20;
  395. end
  396. else
  397. PrimaryYAxis.YMin := 0;
  398. // Try out the pen styles:
  399. if ChartKind = ckChartStackedBar then
  400. PenStyle[0] := psClear // THIS IS HOW YOU TEMPORARILY HIDE ONE PEN!
  401. else
  402. PenStyle[0] := psSolid;
  403. PenStyle[1] := psDash;
  404. PenStyle[2] := psDot;
  405.  
  406. if MenuSecondaryAxisMode.Checked then
  407. begin
  408. PenCount := 4; // Add a pen for right side demo.
  409. SecondaryYAxis.YMax := 140; // Example shows Q/A percentage. Experimental results
  410. // results are compared to expected results, and the
  411. // response percentage, is plotted from 0% to 140%
  412. // of expected value.
  413.  
  414. SecondaryYAxis.YLegendDecimalPlaces := 2;
  415.  
  416. PenSecondaryAxisFlag[3] := True; // Move pen index 3 (Fourth pen) to secondary axis.
  417. PenMarkerKind[3] := pmkDiamond;
  418. PenValueLabels[3] := true; // Label with text.
  419. PenStyle[3] := psClear; // Markers only, no lines.
  420. PenColor[3] := clGray;
  421. MarkerSize := 5; // Make 'em bigger.
  422. end
  423. else
  424. begin
  425. PenCount := 3;
  426. MarkerSize := 3; // Make 'em little
  427. end;
  428.  
  429. PenLegends.Clear;
  430. PenLegends.Add('HgT');
  431. PenLegends.Add('Hg0');
  432. PenLegends.Add('Hg2+');
  433. if MenuSecondaryAxisMode.Checked then
  434. PenLegends.Add('Quality%');
  435.  
  436. PenUnit.Clear;
  437. PenUnit.Add('ug/m3');
  438. PenUnit.Add('ug/m3');
  439. PenUnit.Add('ug/m3');
  440. if MenuSecondaryAxisMode.Checked then
  441. PenUnit.Add('%'); // Optional Pen in percentage scale.
  442.  
  443. //ShowLegend := TRUE;
  444. Legend := clChartLegendBelow;
  445.  
  446. //ChartKind := ckChartLine;
  447. end;
  448. // Chart.AutoFormatGraph;
  449. Chart.PlotGraph;
  450.  
  451. //Chart.ResizeChartCanvas;
  452. end;
  453.  
  454. procedure TJvChartDemoForm.FormResize(Sender: TObject);
  455. begin
  456. if Assigned(Chart) then
  457. Chart.ResizeChartCanvas;
  458. end;
  459.  
  460. procedure TJvChartDemoForm.ButtonBarChartClick(Sender: TObject);
  461. begin
  462. Chart.Options.ChartKind := ckChartBar;
  463. NewValues;
  464. //Chart.PlotGraph;
  465. end;
  466.  
  467. procedure TJvChartDemoForm.ButtonLineClick(Sender: TObject);
  468. var
  469. I: Integer;
  470. begin
  471. Chart.Options.ChartKind := ckChartLine;
  472. for I := 0 to Chart.Options.PenCount - 1 do
  473. begin
  474. Chart.Options.PenMarkerKind[I] := pmkNone;
  475. end;
  476.  
  477. NewValues;
  478. end;
  479.  
  480. procedure TJvChartDemoForm.ButtonLineMarkerClick(Sender: TObject);
  481. //var
  482. // I:Integer;
  483. begin
  484. Chart.Options.ChartKind := ckChartLine;
  485. Chart.Options.PenMarkerKind[0] := pmkDiamond; // demonstrate both Diamond and Circle Marks.
  486. Chart.Options.PenMarkerKind[1] := pmkDiamond;
  487. Chart.Options.PenMarkerKind[2] := pmkCircle;
  488.  
  489. NewValues;
  490. end;
  491.  
  492. procedure TJvChartDemoForm.ButtonStackedBarAveClick(Sender: TObject);
  493. begin
  494. Chart.Options.ChartKind := ckChartStackedBarAverage;
  495. NewValues;
  496. end;
  497.  
  498. procedure TJvChartDemoForm.ButtonStackedBarClick(Sender: TObject);
  499. begin
  500. Chart.Options.ChartKind := ckChartStackedBar;
  501. NewValues;
  502. end;
  503.  
  504. procedure TJvChartDemoForm.SpeedButton7Click(Sender: TObject);
  505. begin
  506. // Chart.PivotData; // TODO: This causes exceptions. not sure why we want this.
  507. end;
  508.  
  509. procedure TJvChartDemoForm.ButtonBarAveClick(Sender: TObject);
  510. begin
  511. //Chart.ShowAsBarWithAve;
  512. Chart.Options.ChartKind := ckChartBarAverage;
  513.  
  514. NewValues;
  515. //Chart.Plo
  516. end;
  517.  
  518. procedure TJvChartDemoForm.ButtonPieClick(Sender: TObject);
  519. begin
  520. // Chart.ShowAsPie;
  521. Chart.Options.ChartKind := ckChartPieChart;
  522. end;
  523.  
  524. procedure TJvChartDemoForm.ButtonMarkersClick(Sender: TObject);
  525. begin
  526. //Chart.ShowAsMark;
  527. Chart.Options.ChartKind := ckChartMarkers;
  528. end;
  529.  
  530. procedure TJvChartDemoForm.SpinEdit1Change(Sender: TObject);
  531. begin
  532. // Chart.Options.ColorScheme := SpinEdit1.Value;
  533. // Chart.PlotGraph;
  534. end;
  535.  
  536. procedure TJvChartDemoForm.Button2Click(Sender: TObject);
  537. begin
  538. Chart.PlotGraph;
  539. end;
  540.  
  541. procedure TJvChartDemoForm.Button4Click(Sender: TObject);
  542. begin
  543. // Chart.AutoFormatGraph; WAP Removed. BAD CODE.
  544. Chart.PlotGraph;
  545. end;
  546.  
  547. procedure TJvChartDemoForm.ButtonDeltaAverageClick(Sender: TObject);
  548. begin
  549. Chart.Options.ChartKind := ckChartDeltaAverage;
  550. end;
  551.  
  552. procedure TJvChartDemoForm.FormCreate(Sender: TObject);
  553. begin
  554. FStatHgt := TStatArray.Create(10); // Initialize for rolling average of last 10 samples.
  555. FStatHg0 := TStatArray.Create(10);
  556.  
  557. if Assigned(Chart) then
  558. // Chart.ShowAsLineWithMark;
  559. NewValues;
  560. end;
  561.  
  562. procedure TJvChartDemoForm.Panel2DblClick(Sender: TObject);
  563. begin
  564. ShellExecute(HWND(nil), 'show', 'http://homepages.borland.com/jedi/jvcl/', nil, nil, SW_SHOW);
  565. end;
  566.  
  567. procedure TJvChartDemoForm.ShowgapinLineChart1Click(Sender: TObject);
  568. begin
  569. ShowgapinLineChart1.Checked := not ShowgapinLineChart1.Checked;
  570. ButtonLine.Down := true;
  571. NewValues;
  572. end;
  573.  
  574. procedure TJvChartDemoForm.Print1Click(Sender: TObject);
  575. begin
  576. if PrintDialog1.Execute then
  577. Chart.PrintGraph;
  578. end;
  579.  
  580. procedure TJvChartDemoForm.Generatenewrandomvalues1Click(Sender: TObject);
  581. begin
  582. if SpeedButtonTestMouseOver.Down then exit;
  583.  
  584. NewValues;
  585. end;
  586.  
  587. procedure TJvChartDemoForm.CopyToClipboard1Click(Sender: TObject);
  588. begin
  589. Chart.GraphToClipboard;
  590. end;
  591.  
  592. procedure TJvChartDemoForm.SetHeaderFont1Click(Sender: TObject);
  593. begin
  594. {Get the current font for the Header text...}
  595. FontDialog1.Font.Assign(Chart.Options.AxisFont);
  596.  
  597. if FontDialog1.Execute then
  598. {Set the font for the Header text...}
  599. Chart.Options.AxisFont := FontDialog1.Font;
  600. Chart.PlotGraph;
  601. Chart.Invalidate;
  602. end;
  603.  
  604. procedure TJvChartDemoForm.About1Click(Sender: TObject);
  605. begin
  606. Application.MessageBox(PChar(
  607. 'JvChart comes from AABSoft Graph written by M?rten Henrichson, JVCL 3.0 ' +
  608. 'version by Warren Postma. '), 'About JvChart', MB_OK);
  609. end;
  610.  
  611. procedure TJvChartDemoForm.AboutJVCL301Click(Sender: TObject);
  612. begin
  613. TJvJVCLAboutForm.Execute(False);
  614. end;
  615.  
  616. procedure TJvChartDemoForm.Scrolling1Click(Sender: TObject);
  617. begin
  618. if SpeedButtonTestMouseOver.Down then exit;
  619.  
  620. Scrolling1.Checked := not Scrolling1.Checked;
  621. Timer1.Enabled := Scrolling1.Checked;
  622. end;
  623.  
  624. procedure TJvChartDemoForm.Timer1Timer(Sender: TObject);
  625. begin
  626. if SpeedButtonTestMouseOver.Down then exit;
  627.  
  628. Chart.Data.Scroll;
  629. _Generate;
  630. _StoreValue(Chart.Data.ValueCount - 1);
  631. Chart.PlotGraph;
  632. end;
  633.  
  634. procedure TJvChartDemoForm.ShowDataInListbox1Click(Sender: TObject);
  635. begin
  636. ShowDataInListbox1.Checked := not ShowDataInListbox1.Checked;
  637. ListBox1.Visible := ShowDataInListbox1.Checked;
  638.  
  639. if not ShowDataInListbox1.Checked then
  640. begin
  641. Chart.CursorPosition := -1; // Invisible.
  642. end;
  643. end;
  644.  
  645. procedure TJvChartDemoForm.LargeDataset576samples1Click(Sender: TObject);
  646. begin
  647. if SpeedButtonTestMouseOver.Down then exit;
  648.  
  649. LargeDataset576samples1.Checked := not LargeDataset576samples1.Checked;
  650. NewValues;
  651. end;
  652.  
  653. procedure TJvChartDemoForm.DateTimeAxisModeClick(Sender: TObject);
  654. begin
  655. DateTimeAxisMode.Checked := not DateTimeAxisMode.Checked;
  656. if SpeedButtonTestMouseOver.Down then begin
  657. Chart.Options.XLegends.Clear;
  658. end else
  659. NewValues;
  660. end;
  661.  
  662. procedure TJvChartDemoForm.FormDestroy(Sender: TObject);
  663. begin
  664. FreeAndNil(FStatHgt);
  665. FreeAndNil(FStatHg0);
  666. end;
  667.  
  668. procedure TJvChartDemoForm.PrintOptions1Click(Sender: TObject);
  669. begin
  670. PrinterSetupDialog1.Execute;
  671. end;
  672.  
  673. procedure TJvChartDemoForm.MenuSecondaryAxisModeClick(Sender: TObject);
  674. begin
  675. MenuSecondaryAxisMode.Checked := not MenuSecondaryAxisMode.Checked;
  676.  
  677. if MenuSecondaryAxisMode.Checked then
  678. begin
  679. ButtonLine.Down := true;
  680. ButtonLineClick(Sender);
  681. end
  682. else
  683. NewValues;
  684. end;
  685.  
  686. procedure TJvChartDemoForm.ListBox1DblClick(Sender: TObject);
  687. begin
  688. Chart.CursorPosition := ListBox1.ItemIndex; // Highlight one sample.
  689. end;
  690.  
  691. procedure TJvChartDemoForm.ListBox1Click(Sender: TObject);
  692. begin
  693. Chart.CursorPosition := ListBox1.ItemIndex; // Highlight one sample.
  694. end;
  695.  
  696. procedure TJvChartDemoForm.MenuNegValueTestClick(Sender: TObject);
  697. begin
  698. FNegValueFlag := MenuNegValueTest.Checked;
  699. NewValues;
  700. end;
  701.  
  702. { Simple Chart Tests for finding bug }
  703. procedure TJvChartDemoForm.SpeedButtonTestMouseOverClick(Sender: TObject);
  704. var
  705. i:Integer;
  706. n:Double;
  707. marker1,marker2,draggableCursor:TJvChartFloatingMarker;
  708. begin
  709. ListBox1.Clear;
  710. Scrolling1.Checked := false;
  711.  
  712. Chart.Options.Title := 'Click on the Red Diamonds or the vertical gray line and Drag them!';
  713. Chart.Options.ChartKind := ckChartLine;
  714. Chart.Options.XLegends.Clear;
  715. Chart.Options.XAxisHeader := '';
  716.  
  717. Chart.Options.MouseDragObjects := true; // NEW: MOUSE DRAG FLOATING OBJECTS!
  718.  
  719. for i := 0 to Chart.Options.PenCount - 1 do
  720. begin
  721. Chart.Options.PenMarkerKind[I] := pmkNone;
  722. end;
  723. Chart.Data.Clear;
  724. Chart.Options.XValueCount := 80;
  725. Chart.Data.ValueCount := 6;
  726. Chart.Options.PenCount := 1;
  727. for i := 0 to Chart.Options.XValueCount-1 do begin
  728. n := 30-(25*((1-((i-25)/15))*(1-((i-25)/15))));
  729. if n<5 then
  730. n := 5 -(Sqrt((Abs(n))/15));
  731. ListBox1.Items.Add( FloatToStrF(n,ffFixed,6,4));
  732. Chart.Data.Value[0,i] := n;
  733. end;
  734. Chart.Options.PrimaryYAxis.YMax := 50;
  735.  
  736. Chart.Options.PenStyle[0] := psSolid;
  737.  
  738. // NEW: Add a floating marker:
  739. marker1 := Chart.AddFloatingMarker;
  740. marker1.XPosition := 13;
  741. marker1.YPosition := Chart.Data.Value[0,marker1.XPosition]; // Snap to Pen 1
  742. marker1.XDraggable := true; // make it mouse-moveable.
  743. marker1.YDraggable := true;
  744. marker1.Caption :='Start';
  745. marker1.Visible := true;
  746.  
  747.  
  748. marker2 := Chart.AddFloatingMarker;
  749. marker2.XPosition := 66;
  750. marker2.YPosition := Chart.Data.Value[0,marker2.XPosition]; // Snap to Pen 1
  751. marker2.LineToMarker := marker1.index; // Connect with a line to marker1
  752. marker2.XDraggable := true; // make it mouse-moveable.
  753. marker2.YDraggable := true;
  754. marker2.Caption := 'End';
  755. marker2.Visible := true;
  756.  
  757. // NOTE: Do not Free marker1 or marker2.
  758. // Marker objects are freed automatically
  759. // by the Chart.
  760.  
  761. // a draggable cursor object:
  762. draggableCursor := Chart.AddFloatingMarker;
  763. draggableCursor.LineVertical := true; // Make a vertical Line
  764. draggableCursor.Marker := pmkNone; // No marker. So it is a line only.
  765. draggableCursor.XDraggable := true; // make it draggable.
  766. draggableCursor.XPosition := 40;
  767. draggableCursor.LineColor := clDkGray;
  768. draggableCursor.LineStyle := psSolid;
  769. draggableCursor.LineWidth := 2;
  770. draggableCursor.Caption := FloatToStrF( Chart.Data.Value[0,draggableCursor.XPosition], ffFixed, 6,4 );
  771. draggableCursor.Visible := true;
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778. Chart.PlotGraph;
  779.  
  780.  
  781. end;
  782.  
  783. procedure TJvChartDemoForm.ChartEndFloatingMarkerDrag(Sender: TJvChart;
  784. FloatingMarker: TJvChartFloatingMarker);
  785. begin
  786. // Snap to line:
  787. if (FloatingMarker.Index<2) then // One of the first two markers?
  788. FloatingMarker.YPosition := Chart.Data.Value[0, FloatingMarker.XPosition]
  789. else // update caption
  790. FloatingMarker.Caption := FloatToStrF( Chart.Data.Value[0,FloatingMarker.XPosition],ffFixed,6,4 );
  791.  
  792.  
  793. end;
  794.  
  795. procedure TJvChartDemoForm.ChartBeginFloatingMarkerDrag(Sender: TJvChart;
  796. FloatingMarker: TJvChartFloatingMarker);
  797. begin
  798. if FloatingMarker.Index=2 then
  799. FloatingMarker.Caption := '?';
  800.  
  801. end;
  802.  
  803. procedure TJvChartDemoForm.ChartChartPaint(Sender: TJvChart;
  804. aCanvas: TCanvas);
  805. begin
  806. aCanvas.Pen.Color := clRed;
  807. aCanvas.Pen.Style := psSolid;
  808. aCanvas.MoveTo(0,0);
  809. aCanvas.LineTo(100,100);
  810. end;
  811.  
  812. end.
  813.  
  814.