欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

TChart-对象查看器与打印预览

程序员文章站 2022-06-09 17:28:39
界面代码: object Form1: TForm1 Left = 568 Top = 393 Width = 725 Height = 408 Caption = '对象观察器' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color ......

TChart-对象查看器与打印预览

 

 界面代码:

object form1: tform1
  left = 568
  top = 393
  width = 725
  height = 408
  caption = '对象观察器'
  color = clbtnface
  font.charset = default_charset
  font.color = clwindowtext
  font.height = -11
  font.name = 'ms sans serif'
  font.style = []
  oldcreateorder = false
  onactivate = formactivate
  oncreate = formcreate
  pixelsperinch = 96
  textheight = 13
  object chart1: tchart
    left = 0
    top = 0
    width = 505
    height = 330
    border.width = 2
    border.visible = true
    bottomwall.gradient.endcolor = 6308951
    bottomwall.gradient.midcolor = 13529477
    bottomwall.gradient.startcolor = 2514871
    bottomwall.gradient.visible = true
    gradient.balance = 74
    gradient.direction = gdbottomtop
    gradient.endcolor = clwhite
    gradient.startcolor = claqua
    gradient.visible = true
    leftwall.gradient.balance = 74
    leftwall.gradient.direction = gdbottomtop
    leftwall.gradient.endcolor = clblack
    leftwall.gradient.midcolor = 16744576
    leftwall.gradient.startcolor = clblack
    leftwall.gradient.visible = true
    legend.checkboxesstyle = cbsradio
    title.font.color = clblack
    title.text.strings = (
      '组件测试:水果产量')
    bottomaxis.title.caption = '品名'
    chart3dpercent = 30
    leftaxis.title.caption = '数量'
    align = alleft
    bevelouter = bvnone
    taborder = 0
    anchors = [akleft, aktop, akright, akbottom]
    printmargins = (
      15
      13
      15
      13)
    object series1: tbarseries
      coloreachpoint = true
      marks.callout.brush.color = clblack
      marks.gradient.visible = true
      marks.style = smslabelvalue
      marks.visible = true
      percentformat = '##0,## %'
      barstyle = bsrectgradient
      gradient.direction = gdtopbottom
      gradient.midcolor = 16059031
      gradient.startcolor = 14540754
      xvalues.name = 'x'
      xvalues.order = loascending
      yvalues.name = 'bar'
      yvalues.order = lonone
    end
  end
  object teeinspector1: tteeinspector
    left = 505
    top = 0
    width = 212
    height = 330
    align = alclient
    fixedcols = 1
    rowcount = 8
    fixedrows = 0
    options = [gofixedvertline, govertline, gohorzline, gocolsizing, gothumbtracking]
    taborder = 1
    items = <
      item
        caption = '3d'
        value = true
        onchange = teeinspector1items0change
      end
      item
        caption = '标签'
        value = true
        onchange = teeinspector1items1change
      end
      item
        caption = '图例'
        value = true
        onchange = teeinspector1items2change
      end
      item
        caption = '横坐标'
        style = iistring
        value = '品名'
        onchange = teeinspector1items3change
      end
      item
        caption = '纵坐标'
        style = iistring
        value = '数量'
        onchange = teeinspector1items4change
      end
      item
        caption = '字颜色'
        style = iicolor
        value = 0
        onchange = teeinspector1items5change
      end
      item
        caption = '图表标题'
        style = iistring
        value = '组件测试:水果产量'
        onchange = teeinspector1items6change
      end>
    header.font.color = clnavy
    header.font.gradient.visible = true
    colwidths = (
      82
      126)
    rowheights = (
      19
      19
      19
      19
      19
      19
      19
      19)
  end
  object panel1: tpanel
    left = 0
    top = 330
    width = 717
    height = 41
    align = albottom
    taborder = 2
    object label1: tlabel
      left = 16
      top = 11
      width = 49
      height = 13
      autosize = false
      caption = '种类:'
    end
    object comboflat1: tcomboflat
      left = 72
      top = 8
      width = 153
      bevelkind = bksoft
      color = clwhite
      itemindex = 0
      taborder = 0
      text = '苹果'
      onchange = comboflat1change
      items.strings = (
        '苹果'
        '桔子'
        '梨'
        '葡萄'
        '甘蔗'
        '西瓜')
    end
    object button1: tbutton
      left = 344
      top = 8
      width = 75
      height = 25
      caption = '&r.返回'
      taborder = 1
      onclick = button1click
    end
    object button2: tbutton
      left = 264
      top = 8
      width = 75
      height = 25
      caption = '&p.打印'
      taborder = 2
      onclick = button2click
    end
  end
  object chartpreviewer1: tchartpreviewer
    chart = chart1
    title = '打印...'
    left = 232
    top = 201
  end
end

功能代码

unit unit1;

interface

uses
  windows, messages, sysutils, variants, classes, graphics, controls, forms,
  dialogs, teeedit, stdctrls, tecanvas, extctrls, grids, teeinspector,
  teengine, series, teeprocs, chart;

type
  tform1 = class(tform)
    chart1: tchart;
    series1: tbarseries;
    teeinspector1: tteeinspector;
    panel1: tpanel;
    label1: tlabel;
    comboflat1: tcomboflat;
    button1: tbutton;
    button2: tbutton;
    chartpreviewer1: tchartpreviewer;
    procedure button1click(sender: tobject);
    procedure comboflat1change(sender: tobject);
    procedure formactivate(sender: tobject);
    procedure teeinspector1items0change(sender: tobject);
    procedure teeinspector1items1change(sender: tobject);
    procedure teeinspector1items2change(sender: tobject);
    procedure teeinspector1items3change(sender: tobject);
    procedure teeinspector1items4change(sender: tobject);
    procedure teeinspector1items6change(sender: tobject);
    procedure teeinspector1items5change(sender: tobject);
    procedure button2click(sender: tobject);
    procedure formcreate(sender: tobject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  form1: tform1;

implementation

{$r *.dfm}

procedure tform1.button1click(sender: tobject);
begin
  close;
end;

procedure tform1.comboflat1change(sender: tobject);
begin
  (*
    苹果
    桔子
    梨
    葡萄
    甘蔗
    西瓜
  *)
  with series1 do
  begin
    clear;
    case comboflat1.itemindex of
      0: addxy(1, 300, '苹果');
      1: addxy(1, 280, '桔子');
      2: addxy(1, 450, '梨');
      3: addxy(1, 340, '葡萄');
      4: addxy(1, 780, '甘蔗');
      5: addxy(1, 280, '习惯');
      6: addxy(1, 890, '柿子');
    end;
  end;
end;

procedure tform1.formactivate(sender: tobject);
begin
  series1.addxy(1, 300, '苹果');
end;

procedure tform1.teeinspector1items0change(sender: tobject);
begin
  chart1.view3d := teeinspector1.items[0].value;
end;

procedure tform1.teeinspector1items1change(sender: tobject);
begin
  series1.marks.visible := teeinspector1.items[1].value;
end;

procedure tform1.teeinspector1items2change(sender: tobject);
begin
  chart1.legend.visible := teeinspector1.items[2].value;
end;

procedure tform1.teeinspector1items3change(sender: tobject);
begin
  chart1.bottomaxis.title.caption := teeinspector1.items[3].value;
end;

procedure tform1.teeinspector1items4change(sender: tobject);
begin
  chart1.leftaxis.title.caption := teeinspector1.items[4].value;
end;


procedure tform1.teeinspector1items5change(sender: tobject);
begin
  chart1.title.font.color := teeinspector1.items[5].value;
  chart1.bottomaxis.title.font.color := teeinspector1.items[5].value;
  chart1.leftaxis.title.font.color := teeinspector1.items[5].value;
  chart1.refresh;
end;


procedure tform1.teeinspector1items6change(sender: tobject);
begin
  chart1.title.text.text := teeinspector1.items[6].value;
end;

procedure tform1.button2click(sender: tobject);
begin
  chartpreviewer1.execute;
end;

procedure tform1.formcreate(sender: tobject);
begin
  self.position := poscreencenter;
end;

end.