没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2020-05-18 11:17:29.860|阅读 671 次
概述:FastReport VCL是用于Delphi,C ++ Builder,RAD Studio和Lazarus的报告和文档创建VCL库。本文是关于它的一个实例:将JSON格式的股票报价生成了一份报告。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
报表生成器FastReport VCL是用于在您的软件中集成商务智能的现代解决方案。它提供了可视化模板设计器,可以访问最受欢迎的数据源,报告引擎,预览,将过滤器导出为30多种格式,并可以部署到云,Web,电子邮件和打印中。
近日,FastReport VCL升级到v6.6版,在此版本中,所有面板隐藏在“Data Tree”数据树,添加了新的线性条形码类型:Pharmacode,改进了预览窗口中的搜索,感兴趣的朋友可点击下方按钮下载最新版。
您可以点击此处,下载本文教程完整的演示Demo。
根据文档要求,为了获得股票报价,需要使用GET请求“历史记录”
创建一个应用程序并将组件添加到表单中:
frxReport1: TfrxReport; JSON_DS: TfrxUserDataSet; ButtonConnectToJSON: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; ComboBoxName: TComboBox; ComboBoxResolution: TComboBox; DateTimePickerFrom: TDateTimePicker; Label4: TLabel; DateTimePickerTo: TDateTimePicker; ButtonShowReport: TButton; Image1: TImage; Label5: TLabel; StatusBar1: TStatusBar; ButtonDesign: TButton; frxDesigner1: TfrxDesigner; frxChartObject1: TfrxChartObject; frxPDFExport1: TfrxPDFExport;
将项目添加到ComboBoxName和ComboBoxResolution
ComboBoxName.Items := 'GAZP SBER BRENT MOEX ROSN YNDX RUAL'; ComboBoxResolution.Items := '1 5 15 30 45 60 120 180 240 D W M';
添加全局变量
var tHTTP: TfrxTransportHTTP; frxJSON: TfrxJSON; Res: String; Symbol,Resolution,FromCandlesHistory,ToCandlesHistory : String; frxJSONArrayT,frxJSONArrayC,frxJSONArrayO, frxJSONArrayH,frxJSONArrayL,frxJSONArrayV: TfrxJSONArray; S: TStringStream;
在ButtonConnectToJSON按钮的Click事件中,编写以下代码:
procedure TFormJSON.ButtonConnectToJSONClick(Sender: TObject); begin frxReport1.LoadFromFile('ChartJSON.fr3'); JSON_DS.RangeEnd := reCount; Symbol := ComboBoxName.Items[ComboBoxName.ItemIndex]; Resolution := ComboBoxResolution.Items[ComboBoxResolution.ItemIndex]; FromCandlesHistory := DateTimeToUnix(DateTimePickerFrom.DateTime).ToString; ToCandlesHistory := DateTimeToUnix(DateTimePickerTo.DateTime).ToString; //Creating a TfrxTransportHTTP Object for a GET Request over HTTPS tHTTP := TfrxTransportHTTP.Create(nil); try //We form a GET request string and get a response in JSON format Res := tHTTP.Get('//api.bcs.ru/udfdatafeed/v1/history?symbol=' +Symbol+ '&resolution='+Resolution + '&from='+ FromCandlesHistory+ '&to='+ToCandlesHistory); // if JSON is received incorrectly, then load it from the file and display a message in StatusBarr if (Res = '') or (pos('"s":"ok"',Res) = 0) then begin StatusBar1.SimpleText := 'Error loading JSON'; S := TStringStream.Create('', TEncoding.UTF8); try S.LoadFromFile('JSON/'+Symbol+'.json'); finally Res:= S.DataString; FreeAndNil(S); end; StatusBar1.SimpleText := 'Successful JSON loading from file '+Symbol+'.json'; end else begin StatusBar1.SimpleText := 'Successful JSON('+Symbol+') loading'; end; // We load the received JSON from the Res line into the frxJSON object: TfrxJSON frxJSON := TfrxJSON.Create(Res); try if frxJSON.IsValid then begin StatusBar1.SimpleText :=StatusBar1.SimpleText +' /JSON is Valid'; // Read arrays if frxJSON.IsNameExists('t') then frxJSONArrayT := TfrxJSONArray.Create(frxJSON.ObjectByName('t')); frxJSONArrayC := TfrxJSONArray.Create(frxJSON.ObjectByName('c')); frxJSONArrayO := TfrxJSONArray.Create(frxJSON.ObjectByName('o')); frxJSONArrayH := TfrxJSONArray.Create(frxJSON.ObjectByName('h')); frxJSONArrayL := TfrxJSONArray.Create(frxJSON.ObjectByName('l')); frxJSONArrayV := TfrxJSONArray.Create(frxJSON.ObjectByName('v')); // Prepare JSON_DS by clearing and adding fields JSON_DS.Fields.Clear; JSON_DS.Fields.Add('Ticker'); JSON_DS.Fields.Add('Date'); JSON_DS.Fields.Add('Time'); JSON_DS.Fields.Add('Open'); JSON_DS.Fields.Add('Close'); JSON_DS.Fields.Add('High'); JSON_DS.Fields.Add('Low'); JSON_DS.Fields.Add('Vol'); JSON_DS.RangeEndCount := frxJSONArrayT.Count; end else StatusBar1.SimpleText :=StatusBar1.SimpleText +' /JSON is Invalid'; finally end; finally end; end;
要通过JSON_DS组件TfrxUserDataSet从数组frxJSONArrayT,frxJSONArrayC,frxJSONArrayO,frxJSONArrayH,frxJSONArrayL,frxJSONArrayV生成报告时获取数据,需要使用OnGetValue事件:
procedure TFormJSON.JSON_DSGetValue(const VarName: string; var Value: Variant); var Item: string; Time : string; begin Item := frxJSONArrayT.GetString(JSON_DS.RecNo); DateTimeToString(Time, 't', UnixToDateTime(StrToInt64(Item))); if VarName = 'Ticker' then begin Value := Symbol; exit; end else if VarName = 'Date' then begin Value := DateToStr(UnixToDateTime(StrToInt64(Item)))+' '+Time; exit; end else if VarName = 'Time' then begin Value := Time; exit; end else if VarName = 'Open' then Item := frxJSONArrayO.GetString(JSON_DS.RecNo) else if VarName = 'Close' then Item := frxJSONArrayC.GetString(JSON_DS.RecNo) else if VarName = 'High' then Item := frxJSONArrayH.GetString(JSON_DS.RecNo) else if VarName = 'Low' then Item := frxJSONArrayL.GetString(JSON_DS.RecNo) else if VarName = 'Vol' then Item := frxJSONArrayV.GetString(JSON_DS.RecNo); Value := Item; end;
接下来,在报表设计器中创建一个模板,将其命名为ChartJSON.fr3并将JSON_DS连接到它。
要显示图表,请使用TeeChart Pro VCL软件包中的Candle系列,并连接到JSON_DS。
接下来,为其余按钮添加Click事件处理程序:
procedure TFormJSON.ButtonDesignClick(Sender: TObject); begin if (Res = '') then ButtonConnectToJSON.Click; frxReport1.DesignReport(); end; procedure TFormJSON.ButtonShowReportClick(Sender: TObject); begin if (Res = '') then ButtonConnectToJSON.Click; frxReport1.ShowReport(); end;
我们还为ComboBoxName,DateTimePickerFrom和DateTimePickerTo添加了Change事件处理程序:
procedure TFormJSON.ComboBoxNameChange(Sender: TObject); begin ButtonConnectToJSON.Click; end; procedure TFormJSON.DateTimePickerFromChange(Sender: TObject); begin ButtonConnectToJSON.Click; end; procedure TFormJSON.DateTimePickerToChange(Sender: TObject); begin ButtonConnectToJSON.Click; end;
同样,在关闭应用程序时,请不要忘记释放已使用对象的内存。
procedure TFormJSON.FormClose(Sender: TObject; var Action: TCloseAction); begin tHTTP.Free; frxJSON.Free; frxJSONArrayT.Free; frxJSONArrayC.Free; frxJSONArrayO.Free; frxJSONArrayH.Free; frxJSONArrayL.Free; frxJSONArrayV.Free; end;
接下来,运行应用程序。
在此应用中,您可以选择所需的股票。
还可以使用日历选择所需的日期范围。
当单击“连接到JSON”,“显示报告”或“ D”按钮时,以及更改共享的日期或名称时,都会发生与JSON的连接,并显示有关连接状态的消息。
当单击“显示报告”按钮时,将生成一个报告并显示其预览。
恭喜,您使用GET请求收到了JSON格式的股票报价,并将JSON连接到FastReport VCL 6并生成了一个报告。
还想要更多吗?您可以点击阅读【FastReport 报表2019最新资源盘点】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入FastReport技术交流群(783996712),我们很高兴为您提供查询和咨询。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@dpuzeg.cn
本教程演示DevExpress WinForms的Banded Grid View 是如何进行用户自定义的,欢迎下载最新版组件体验!
可视化项目时间线对于有效规划和跟踪至关重要。在本篇教程中,您将学习如何使用 C# 在 Excel 中创建组合图,只需几行代码,即可自动生成动态、美观的组合图。
本文将为大家介绍DevExpress XAF将.NET Aspire集成到Blazor项目中后如何实现数据库依赖,欢迎下载最新版组件体验!
FP3 文件是使用流行的报表生成工具FastReport创建的报表。这种格式广泛用于存储可立即查看的报表数据,这些数据可以轻松共享或保存以供日后分析。但是,要打开和查看此类文件,需要一个特殊的程序——FastReport Viewer。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@dpuzeg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢