博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通用图形分析
阅读量:6569 次
发布时间:2019-06-24

本文共 5175 字,大约阅读时间需要 17 分钟。

{*******************************************************}

{                                                       }
{       图形分析                                        }
{                                                       }
{       版权所有 (C) 2008 咏南工作室(陈新光)            }
{                                                       }
{*******************************************************}

unit uChart;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, DBChart, StdCtrls,db,Series,
  Buttons;

type

  TColParams = record
    FieldName: string;
    Title: string;
  end;
  TFormChart = class(TForm)
    Panel1: TPanel;
    DBChart1: TDBChart;
    RadioGroup1: TRadioGroup;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FFirstRun:Boolean;
    ColArray,ColArray2: array of TColParams;
    FDataSet:TDataSet;
    FTitle:string;
    Bar:TBarSeries;              //柱形
    Pie:TPieSeries;              //饼形
    Area:TAreaSeries;            //领域图
    FastLine:TFastLineSeries;    //曲线图
    procedure CreateSeries;
    procedure CreateChart;
    procedure FillField;
    function GetLableFieldName:string;
    function GetValueFieldName:string;
    { Private declarations }
  public
    { Public declarations }
  end;

var

  FormChart: TFormChart;

const

  FLable='请录入标识字段';
  FValue='请录入统计字段';

//==============================================================================

// ATitle: TDBChart.title
//==============================================================================

procedure ShowChart(ADataSet:TDataSet;ATitle:string='');

implementation

{$R *.dfm}

procedure ShowChart(ADataSet:TDataSet;ATitle:string='');

begin
  FormChart:=TFormChart.Create(nil);
  try
    FormChart.FDataSet:=ADataSet;
    FormChart.FTitle:=ATitle;
    FormChart.RadioGroup1.ItemIndex:=0;
    FormChart.DBChart1.Title.Text.Clear;
    FormChart.DBChart1.Title.Text.Add(FormChart.FTitle);
    FormChart.ShowModal;
  finally
    FormChart.Free;
  end;
end;

procedure TFormChart.BitBtn1Click(Sender: TObject);

begin
//  DBChart1.FreeAllSeries();
  FFirstRun:=False;
  CreateChart;
end;

procedure TFormChart.CheckBox1Click(Sender: TObject);

begin
  DBChart1.View3D:=CheckBox1.Checked;
end;

procedure TFormChart.CreateChart;

begin
  if FFirstRun then exit;

  if Trim(ComboBox1.Text)='' then

  begin
    ShowMessage(FLable);
    Exit;
  end;
  if Trim(ComboBox2.Text)='' then
  begin
    ShowMessage(FValue);
    Exit;
  end;

  DBChart1.SeriesList.Clear;

  DBChart1.View3D:=CheckBox1.Checked;

 
  case RadioGroup1.ItemIndex of
    0:
    begin
      with Bar do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
    1:
    begin
      with Pie do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
    2:
    begin
      with Area do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
    3:
    begin
      with FastLine do
      begin
        ParentChart := DBChart1;
        marks.Style:= smsvalue;
        DataSource := FDataSet;
        XLabelsSource :=GetLableFieldName;
        YValues.ValueSource :=GetValueFieldName;
      end;
    end;
  end;
  FFirstRun:=False;
end;

procedure TFormChart.CreateSeries;

begin
  Bar:=TBarSeries.Create(Self);
  Pie:=TPieSeries.Create(Self);
  Area:=TAreaSeries.Create(Self);
  FastLine:=TFastLineSeries.Create(Self);
end;

procedure TFormChart.FillField;

var
  i:Integer;
begin
  ComboBox1.Items.Clear;
  ComboBox2.Items.Clear;

  SetLength(ColArray,FDataSet.FieldCount);

  SetLength(ColArray2,FDataSet.FieldCount);
 
  for i:=0 to FDataSet.FieldCount-1 do
  begin
    if not (FDataSet.Fields[i] is TNumericField)
      or (FDataSet.Fields[i] is TIntegerField) then
    begin
      ColArray[i].FieldName:=FDataSet.Fields[i].FieldName;
      ColArray[i].Title:=FDataSet.Fields[i].DisplayLabel;
      ComboBox1.Items.Add(ColArray[i].Title);
      if ComboBox1.Items.Count>0 then
        ComboBox1.ItemIndex:=0;
    end else
    begin
      ColArray2[i].FieldName:=FDataSet.Fields[i].FieldName;
      ColArray2[i].Title:=FDataSet.Fields[i].DisplayLabel;
      ComboBox2.Items.Add(ColArray2[i].Title);
      if ComboBox2.Items.Count>0 then
        ComboBox2.ItemIndex:=0;
    end; 
  end;
end;

procedure TFormChart.FormClose(Sender: TObject; var Action: TCloseAction);

begin
  Action:=caFree;
end;

procedure TFormChart.FormCreate(Sender: TObject);

begin
  FFirstRun:=True;
  CreateSeries;
end;

procedure TFormChart.FormDestroy(Sender: TObject);

begin
  FreeAndNil(Bar);
  FreeAndNil(Pie);
  FreeAndNil(Area);
  FreeAndNil(FastLine);
  FormChart:=nil;
end;

procedure TFormChart.FormShow(Sender: TObject);

begin
  FillField;
end;

function TFormChart.GetLableFieldName: string;

var
  i:Integer;
begin
  for i := Low(ColArray) to High(ColArray) do
  begin
    if ColArray[i].Title=ComboBox1.Text then
      Result:=ColArray[i].FieldName;
  end;   
end;

function TFormChart.GetValueFieldName: string;

var
  i:Integer;
begin
  for i := Low(ColArray2) to High(ColArray2) do
  begin
    if ColArray2[i].Title=ComboBox2.Text then
      Result:=ColArray2[i].FieldName;
  end;   
end;

procedure TFormChart.RadioGroup1Click(Sender: TObject);

begin
//  DBChart1.FreeAllSeries();
  CreateChart;
end;

end.

转载地址:http://bepjo.baihongyu.com/

你可能感兴趣的文章
【权值分块】bzoj1503 [NOI2004]郁闷的出纳员
查看>>
【枚举】【二分答案】【分块答案】【BFS】【最大流】【Dinic】bzoj1189 [HNOI2007]紧急疏散evacuate...
查看>>
期末大作业
查看>>
ThreadLocal
查看>>
第一次作业-准备篇
查看>>
cnzz统计代码引起的Bad Request - Request Too Long
查看>>
MinGW安装与使用简介
查看>>
Sublime Text 3 遇到的一些小坑的解决方法
查看>>
JSP之9大对象
查看>>
sql 递归查询
查看>>
KMP C++
查看>>
HDU1506 Largest Rectangle in a Histogram(算竞进阶习题)
查看>>
HTTP响应状态码
查看>>
crushmap磁盘智能分组
查看>>
《算法导论》读书笔记--第三章 函数的增长
查看>>
《利用python进行数据分析》读书笔记--第八章 绘图和可视化
查看>>
栈的操作
查看>>
Flask 备注一(单元测试,Debugger, Logger)
查看>>
ElasticSearch(八):springboot集成ElasticSearch集群并使用
查看>>
Java基础学习_01 概述及环境配置
查看>>