请问如何动态设置(就是在程序运行时设置)DBchart的属性,如datasource,以及datesource中的label、bar属性,谢谢!

解决方案 »

  1.   


      ClearSeries;
      if Not ADOQuery.Active then Exit;
      if LineRadioButton.Checked then //线型图
      begin
        LineSeries := TLineSeries.Create(Self);
        with LineSeries do
        begin
          ParentChart := DBChart;
          DataSource := ADOQuery;
          XLabelsSource := ADOQuery.Fields[0].FieldName;
          YValues.ValueSource := ADOQuery.Fields[1].FieldName;
          Active := True;
          Font.Name := '宋体';
          Font.Size := 9;
        end;
      end else
        if BarRadioButton.Checked then //柱形图
        begin
          BarSeries := TBarSeries.Create(Self);
          with BarSeries do
          begin
            ParentChart := DBChart;
            DataSource := ADOQuery;
            BarStyle := bsRectGradient;
            ColorEachPoint := True;
            XLabelsSource := ADOQuery.Fields[0].FieldName;
            YValues.ValueSource := ADOQuery.Fields[1].FieldName;
            Active := True;
            DBChart.View3DOptions.Orthogonal := True;
            Font.Name := '宋体';
            Font.Size := 9;
          end;
        end else
        begin
          PieSeries := TPieSeries.Create(Self);
          with PieSeries do //饼形图
          begin
            ParentChart := DBChart;
            DataSource := ADOQuery;
            XLabelsSource := ADOQuery.Fields[0].FieldName;
            PieValues.ValueSource := ADOQuery.Fields[1].FieldName;
            Active := True;
            Font.Name := '宋体';
            Font.Size := 9;
          end;
        end;