delphi通过TChart实现各种图表功能


procedure TFrmScsjkb.FormShow(Sender: TObject);
var
  Chart: TChart;  //test
  L,S,F: TChartSeries;//test

  seriesCl,seriesJh: TBarSeries;//TLineSeries;
  seriesQncl,SeriesQnjh,seriesJcZb: TPieSeries;
  seriesMycl,seriesLz,seriesS,seriesF:TLineSeries;
  na:Integer;

  TmpFile: string;

begin


          Image3.Parent.DoubleBuffered:=true;
          Image4.Parent.DoubleBuffered:=true;
          Image5.Parent.DoubleBuffered:=true;
          Image6.Parent.DoubleBuffered:=true;
          Image7.Parent.DoubleBuffered:=true;
          Image8.Parent.DoubleBuffered:=true;
          Image9.Parent.DoubleBuffered:=true;
          Image10.Parent.DoubleBuffered:=true;

      Label24.Caption :=FormatDateTime('yyyy-mm-dd hh:mm',Now());

      proc_c_Chart_Cl14.close;
      proc_c_Chart_Cl14.prepared:=true;
      proc_c_Chart_Cl14.open;


    


      Chart := TChart.Create(nil);
      try

          Chart.Parent := Application.MainForm;
          Chart.Height:=407;
          Chart.Width:=597;
          Chart.Visible := False;


          //Chart.Title.Text.Text := '测试图表';
          S := TBarSeries.Create(Chart);

          Chart.AddSeries(S);

          TBarSeries(Chart.Series[0]).BarWidthPercent:=35;
          TBarSeries(Chart.Series[0]).BarStyle:=bsRectGradient;

          //将数据显示在上面
          S.Marks.Style:=smsValue;
          //不显示数据边框,强制显示数值
          S.Marks.Transparent:=True;
          S.Marks.AutoPosition:=True;
          S.Marks.FontSeriesColor:=True;
          S.Marks.Angle:=45;
          //S.BarStyle:= bsRectGradient;
          //S.Format.BarStyle:=bsRectGradient;

          //S.Title := '嘿嘿';
          proc_c_Chart_Cl14.First;

          while not proc_c_Chart_Cl14.Eof  do
          begin                                                   
              S.Add(proc_c_Chart_Cl14.FieldByName('mrcl').AsFloat,Copy(proc_c_Chart_Cl14.FieldByName('mmdd').AsString,5,4),clMoneyGreen );//clMoneyGreen

              proc_c_Chart_Cl14.Next;
          end;

          Chart.Legend.Visible := False; //数据框隐藏
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue;   $00DB6817  $0032060C
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;

          Chart.LeftAxis.LabelsFormat.Font.Color:=clAqua; //$0000FF80
          Chart.BottomAxis.LabelsFormat.Font.Color:=clAqua;

          Chart.LeftAxis.Grid.Visible:=False;
          Chart.BottomAxis.Grid.Visible:=False;
          Chart.Walls.Visible:=False;


          Chart.LeftAxis.Axis.Color:=clBlue;
          Chart.BottomAxis.Axis.Color:=clBlue;
          //Chart.BottomAxis.LabelsAngle:=270;
          Chart.BottomAxis.LabelsAlternate:=True;
          TmpFile := Application.ExeName + '4.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image4.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;


    proc_c_Chart_Jh14.close;
      proc_c_Chart_Jh14.prepared:=true;
      proc_c_Chart_Jh14.open;


      Chart := TChart.Create(nil);
      try
          Chart.Parent := Application.MainForm;
          Chart.Height:=407;
          Chart.Width:=597;
          Chart.Visible := False;
          //Chart.Title.Text.Text := '测试图表';
          S := TBarSeries.Create(Chart);

          Chart.AddSeries(S);
          TBarSeries(Chart.Series[0]).BarWidthPercent:=35;
          TBarSeries(Chart.Series[0]).BarStyle:=bsRectGradient;

          //将数据显示在上面
          S.Marks.Style:=smsValue;
          S.Marks.Transparent:=True;
          S.Marks.AutoPosition:=True;
          S.Marks.FontSeriesColor:=True;
          S.Marks.Angle:=45;


          proc_c_Chart_Jh14.First;

          while not proc_c_Chart_Jh14.Eof  do
          begin                                                  //
              S.Add(proc_c_Chart_Jh14.FieldByName('mrjh').AsFloat,Copy(proc_c_Chart_Jh14.FieldByName('mmdd').AsString,5,4), clYellow);

              proc_c_Chart_Jh14.Next;
          end;

          Chart.Legend.Visible := False; //数据框隐藏
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue;
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;
          Chart.LeftAxis.LabelsFormat.Font.Color:=clAqua;
          Chart.BottomAxis.LabelsFormat.Font.Color:=clAqua;

          Chart.LeftAxis.Grid.Visible:=False;
          Chart.BottomAxis.Grid.Visible:=False;
          Chart.Walls.Visible:=False;

          Chart.LeftAxis.Axis.Color:=clBlue;
          Chart.BottomAxis.Axis.Color:=clBlue;
          //Chart.BottomAxis.LabelsAngle:=270;
          Chart.BottomAxis.LabelsAlternate:=True;

          TmpFile := Application.ExeName + '3.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image3.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;

  //全年产量


      proc_c_Chart_JhCl_Zb.close;
      proc_c_Chart_JhCl_Zb.prepared:=true;
      proc_c_Chart_JhCl_Zb.open;
      proc_c_Chart_JhCl_Zb.First;

       Chart := TChart.Create(nil);
      try
          Chart.Parent := Application.MainForm;
          Chart.Height:=220;
          Chart.Width:=578;
          Chart.Visible := False;

          S := TPieSeries.Create(Chart);

          Chart.AddSeries(S);

          S.Marks.Visible:=False;
          //S.Title := '嘿嘿';
          S.Add( proc_c_Chart_JhCl_Zb.FieldByName('qncl_hz').AsFloat, '产量', clAqua );  //+FormatFloat('0.00',proc_c_Chart_JhCl_Zb.FieldByName('qncl_hz').AsFloat)
          S.Add( proc_c_Chart_JhCl_Zb.FieldByName('qncl').AsFloat, '产量目标', $00804000 ); //+FormatFloat('0.00',proc_c_Chart_JhCl_Zb.FieldByName('qncl').AsFloat)

          if (proc_c_Chart_JhCl_Zb.FieldByName('qncl_hz').AsFloat >0) and
             (proc_c_Chart_JhCl_Zb.FieldByName('qncl').AsFloat >0)  then
              Label21.Caption := '产量占比:'+FormatFloat('0.00',100*proc_c_Chart_JhCl_Zb.FieldByName('qncl_hz').AsFloat/proc_c_Chart_JhCl_Zb.FieldByName('qncl').AsFloat)+'%'
          else
              Label21.Caption :='';

          //Chart.Legend.Visible := False;
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue;
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;
          TmpFile := Application.ExeName + '5.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image5.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;

  //全年进货

      Chart := TChart.Create(nil);
      try
          Chart.Parent := Application.MainForm;
          Chart.Height:=220;
          Chart.Width:=578;
          Chart.Visible := False;

          S := TPieSeries.Create(Chart);

          Chart.AddSeries(S);
          S.Marks.Visible:=False;
          //S.Title := '嘿嘿';
          S.Add( proc_c_Chart_JhCl_Zb.FieldByName('qnjh_hz').AsFloat, '进货', clAqua );//+FormatFloat('0.00',proc_c_Chart_JhCl_Zb.FieldByName('qnjh_hz').AsFloat)
          S.Add( proc_c_Chart_JhCl_Zb.FieldByName('qnjh').AsFloat, '进货目标', $00804000 );//+FormatFloat('0.00',proc_c_Chart_JhCl_Zb.FieldByName('qnjh').AsFloat)

          if (proc_c_Chart_JhCl_Zb.FieldByName('qnjh_hz').AsFloat >0) and
             (proc_c_Chart_JhCl_Zb.FieldByName('qnjh').AsFloat >0)  then
              Label22.Caption := '进货占比:'+FormatFloat('0.00',100*proc_c_Chart_JhCl_Zb.FieldByName('qnjh_hz').AsFloat/proc_c_Chart_JhCl_Zb.FieldByName('qnjh').AsFloat)+'%'
          else
              Label22.Caption :='';

          //Chart.Legend.Visible := False;
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue;
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;
          TmpFile := Application.ExeName + '8.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image8.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;
         
  //每月产量
       proc_c_Chart_Cl_Month.close;
       proc_c_Chart_Cl_Month.prepared:=true;
       proc_c_Chart_Cl_Month.open;


      Chart := TChart.Create(nil);
      try
        

          Chart.Parent := Application.MainForm;
          Chart.Height:=246;
          Chart.Width:=593;
          Chart.Visible := False;

          S := TBarSeries.Create(Chart);

          Chart.AddSeries(S);

          TBarSeries(Chart.Series[0]).BarWidthPercent:=35;
          TBarSeries(Chart.Series[0]).BarStyle:=bsRectGradient;

          //将数据显示在上面

          S.Marks.Style:=smsValue;
          S.Marks.Transparent:=True;
          S.Marks.AutoPosition:=True;
          S.Marks.FontSeriesColor:=True;
          S.Marks.Angle:=45;

          proc_c_Chart_Cl_Month.First;

          while not proc_c_Chart_Cl_Month.Eof  do
          begin
              S.Add(proc_c_Chart_Cl_Month.FieldByName('mycl').AsFloat,Copy(proc_c_Chart_Cl_Month.FieldByName('ny').AsString,6,2), clMoneyGreen);//clMoneyGreen

              proc_c_Chart_Cl_Month.Next;
          end;

          Chart.Legend.Visible := False;
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue;
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;

          Chart.LeftAxis.LabelsFormat.Font.Color:=clAqua;
          Chart.BottomAxis.LabelsFormat.Font.Color:=clAqua;

          Chart.LeftAxis.Grid.Visible:=False;
          Chart.BottomAxis.Grid.Visible:=False;
          Chart.Walls.Visible:=False;

          Chart.LeftAxis.Axis.Color:=clBlue;
          Chart.BottomAxis.Axis.Color:=clBlue;

          TmpFile := Application.ExeName + '6.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image6.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;


  //当月入炉平均热值,含硫,含氟曲线
       proc_c_Chart_Month_HotSF.close;
       proc_c_Chart_Month_HotSF.prepared:=true;
       proc_c_Chart_Month_HotSF.open;

        Chart := TChart.Create(nil);
      try


         
          Chart.Parent := Application.MainForm;
          Chart.Height:=180;
          Chart.Width:=593;
          Chart.Visible := False;

          L := TLineSeries.Create(Chart);

          Chart.AddSeries(L);

          TLineSeries(Chart.Series[0]).LinePen.Width:=3;
          //TBarSeries(Chart.Series[0]).BarStyle:=bsRectGradient;
          //将数据显示在上面
          //L.Marks.Style:=smsValue;

          proc_c_Chart_Month_HotSF.DisableControls;
          proc_c_Chart_Month_HotSF.First;

          while not proc_c_Chart_Month_HotSF.Eof  do
          begin
               L.Add(proc_c_Chart_Month_HotSF.FieldByName('lz').AsFloat,Copy(proc_c_Chart_Month_HotSF.FieldByName('yymmdd').AsString,9,2), clRed);  //Copy(proc_c_Chart_Cl14.FieldByName('rq').AsString,6,5)
              
               proc_c_Chart_Month_HotSF.Next;
          end;
          proc_c_Chart_Month_HotSF.EnableControls;

          Chart.Legend.Visible := False; //数据框隐藏
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue; //$00DB6817 //$0031080D
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;
          Chart.LeftAxis.LabelsFormat.Font.Color:=clAqua;
          Chart.BottomAxis.LabelsFormat.Font.Color:=clAqua;

          Chart.LeftAxis.Grid.Visible:=False;
          Chart.BottomAxis.Grid.Visible:=False;
          Chart.Walls.Visible:=False;

          Chart.LeftAxis.Axis.Color:=clBlue;
          Chart.BottomAxis.Axis.Color:=clBlue;


          TmpFile := Application.ExeName + '7.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image7.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;


      //含硫含f

        Chart := TChart.Create(nil);
      try

          Chart.Parent := Application.MainForm;
          Chart.Height:=180;
          Chart.Width:=593;
          Chart.Visible := False;

          S := TLineSeries.Create(Chart);
          F := TLineSeries.Create(Chart);

          Chart.AddSeries(S);
          Chart.AddSeries(F);
          TLineSeries(Chart.Series[0]).LinePen.Width:=3;
           TLineSeries(Chart.Series[1]).LinePen.Width:=3;


          proc_c_Chart_Month_HotSF.DisableControls;
          proc_c_Chart_Month_HotSF.First;

          while not proc_c_Chart_Month_HotSF.Eof  do
          begin
               S.Add(proc_c_Chart_Month_HotSF.FieldByName('hs').AsFloat,Copy(proc_c_Chart_Month_HotSF.FieldByName('yymmdd').AsString,9,2), clLime);  //Copy(proc_c_Chart_Cl14.FieldByName('rq').AsString,6,5)

               F.Add(proc_c_Chart_Month_HotSF.FieldByName('hf').AsFloat,Copy(proc_c_Chart_Month_HotSF.FieldByName('yymmdd').AsString,9,2), clYellow);  //Copy(proc_c_Chart_Cl14.FieldByName('rq').AsString,6,5)


              proc_c_Chart_Month_HotSF.Next;
          end;
          proc_c_Chart_Month_HotSF.EnableControls;

          Chart.Legend.Visible := False; //数据框隐藏
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//clBlue; //$00DB6817 //$0031080D
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;
          Chart.LeftAxis.LabelsFormat.Font.Color:=clAqua;
          Chart.BottomAxis.LabelsFormat.Font.Color:=clAqua;

          Chart.LeftAxis.Grid.Visible:=False;
          Chart.BottomAxis.Grid.Visible:=False;
          Chart.Walls.Visible:=False;

          Chart.LeftAxis.Axis.Color:=clBlue;
          Chart.BottomAxis.Axis.Color:=clBlue;

          TmpFile := Application.ExeName + '10.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image10.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;

     

      proc_c_Chart_Today.close;
      proc_c_Chart_Today.prepared:=true;
      proc_c_Chart_Today.open;
      proc_c_Chart_Today.First;

      Chart := TChart.Create(nil);
      try
          Chart.Parent := Application.MainForm;
          Chart.Height:=220;
          Chart.Width:=578;
          Chart.Visible := False;

          S := TPieSeries.Create(Chart);

          Chart.AddSeries(S);
          S.Marks.Visible:=False;

         
          S.Add( proc_c_Chart_Today.FieldByName('jrjc_sl').AsFloat, '已完成', clAqua );
          S.Add( proc_c_Chart_Today.FieldByName('jrjc_slwwc').AsFloat, '未完成', $00804000 );

          if (proc_c_Chart_Today.FieldByName('jrjc_sl').AsFloat+proc_c_Chart_Today.FieldByName('jrjc_slwwc').AsFloat >0) then

              Label23.Caption := '完成占比:'+FormatFloat('0.00',100*proc_c_Chart_Today.FieldByName('jrjc_sl').AsFloat/(proc_c_Chart_Today.FieldByName('jrjc_sl').AsFloat+proc_c_Chart_Today.FieldByName('jrjc_slwwc').AsFloat))+'%'
          else
              Label23.Caption :='';

          //Chart.Legend.Visible := False;
          Chart.View3D := False;
          Chart.BackColor := $0032060C;//$00EFA896    $00DEB469  00612507  0061220D 00A53A16
          Chart.Gradient.StartColor := $0032060C;
          Chart.Gradient.EndColor := $0032060C;
          Chart.Gradient.Visible := True;
          Chart.Walls.Back.Transparent:=True;
          Chart.BevelOuter:=bvNone;

          TmpFile := Application.ExeName + '9.bmp';
          Chart.SaveToBitmapFile(TmpFile);
          Image9.Picture.LoadFromFile(TmpFile);
      finally
          Chart.Free;
      end;

  Label19.Caption:= proc_c_Chart_Today.FieldByName('jrqy_sl').AsString;//今日取样量
  Label20.Caption:= proc_c_Chart_Today.FieldByName('jrjc_sl').AsString;//'今日检测数量'+

  Label11.Caption:= proc_c_Chart_Today.FieldByName('jrjh_jh').AsString;
  Label12.Caption:= proc_c_Chart_Today.FieldByName('jrjh_sj').AsString;
  Label13.Caption:= proc_c_Chart_Today.FieldByName('jrtl_jh').AsString;
  Label14.Caption:= proc_c_Chart_Today.FieldByName('jrtl_sj').AsString;

  Edit2.Text:= proc_c_Chart_Today.FieldByName('eq_lx').AsString;
  Edit3.Text:= proc_c_Chart_Today.FieldByName('eq_total').AsString;
  Edit4.Text:= proc_c_Chart_Today.FieldByName('sq_lx').AsString;
  Edit5.Text:= proc_c_Chart_Today.FieldByName('sq_total').AsString;
  Edit6.SetFocus;
   
end;

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi 10 是一种用于开发 Windows 应用程序的集成开发环境(IDE),其中包含了许多可用于创建图表的组件,其中之一就是 TChart。 TChart 是一个功能强大的图表控件,它允许开发人员轻松地在 Delphi 10 中创建各种类型的图表,如折线图、柱状图、饼图等。TChart 提供了丰富的属性和方法,以方便开发人员自定义图表的外观和行为。 要在 Delphi 10 中使用 TChart,首先需要将该控件添加到窗体中。选择一个适当的容器控件(如 TPanel),然后将 TChart 控件拖放到窗体上。接下来,可以使用属性编辑器或代码来设置图表的属性,例如图表标题、轴标签、图例等。 在将 TChart 添加到窗体后,可以使用 TChart 控件的系列属性来添加要显示的数据。每个数据系列对应于图表中特定的数据集,它可以包含一个或多个数据点。可以通过编辑系列的属性或使用代码来设置数据的值。 一旦设置了图表的属性和数据,可以通过调用 TChart 的方法来绘制和展示图表,例如 TChart.Paint 或 TChart.Invalidate。还可以通过调用 TChart 的其他方法来实现数据更新、缩放、平移等功能。 除了上述基本功能外,TChart 还提供了许多其他功能,如图表的导出和打印、动画效果、交互式操作等。这些功能使得开发人员能够创建出功能丰富、灵活性强的图表应用程序。 总而言之,Delphi 10 中的 TChart 控件为开发人员提供了一个强大而灵活的工具,用于创建各种类型的图表。无论是需要在商务报告中展示数据,还是需要在科学研究中可视化实验结果,TChart 都可以帮助开发人员快速实现他们的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值