Implementar cores em um gráfico

Delphi

04/04/2005

Srs, estou realizando uma manutenção em um sistema desenvolvido em Delphi5 com Paradox, neste sistema tem um módulo de ´indicadores de desenpenho´, no qual é gerado um gráfico que é formado pelo resultado obtido através de fórmulas. O gráfico tem 2 séries, uma é a barra do gráfico e a outra é a linha de ´metas´. O que me foi solicitado é o seguinte: Quando o valor que gera as barras, for menor do que o valor da meta, as barras do gráfico terão que ser formadas na cor vermelho, caso contrário serão verdes. Atualmente as barras são impressas em verde, independente de o valor estiver igual, maior ou menor que a meta. Abaixo estou citando o código do relatório. Como sou iniciante em Delphi, peço ajuda a vcs para possam me ajudar, desde já agradeço.

implementation

{$R *.DFM}

procedure ShowRelIndDesp(nCod:integer);
begin
   with TfrmRelIndDesp.Create(Application) do
      begin
         qryIndic.ParamByName(´COD_IDCD´).Value:=nCod;
         qryIndic.Open;
         qryTipIndic.Open;
         UpdateChart;
         qryDados.First;
         qrpIndDesp.Preview;
         Release;
      end;
end;

procedure TfrmRelIndDesp.UpdateChart;
var i:integer;
begin
   if not qryDados.Locate(´NUM_PARM´,6,[]) then
      exit;
   QRChart1.Chart.Title.Text.Clear;
   QRChart1.Chart.Title.Text.Add(qryIndicDES_IDCD.Value);
   if qryTipIndic.Active and
      ((qryTipIndicCOD_TIPO_IDCD.Value = qryIndicCOD_TIPO_IDCD.Value) or
        qryTipIndic.Locate(´COD_TIPO_IDCD´,qryIndicCOD_TIPO_IDCD.Value,[])) then
      QRChart1.Chart.LeftAxis.Title.Caption:=qryTipIndicDES_EIXO_VERT.Value;
   if qryIndicMAX_SCAL.IsNull then
      begin
         QRChart1.Chart.LeftAxis.Automatic:=true;
      end
   else
      begin
         QRChart1.Chart.LeftAxis.Automatic:=false;
         QRChart1.Chart.LeftAxis.Maximum:=qryIndicMAX_SCAL.Value;
      end;
   if qryIndicVAL_INCR.IsNull then
      QRChart1.Chart.LeftAxis.Increment:=0.1
   else
      QRChart1.Chart.LeftAxis.Increment:=qryIndicVAL_INCR.Value;
   with QRChart1.Chart.Series[0] do
      begin
         Clear;
         Add(qrydadosVAL_JANR.Value,´JAN´,clGreen);
         Add(qryDadosVAL_FEVR.Value,´FEV´,clGreen);
         Add(qryDadosVAL_MARC.Value,´MAR´,clGreen);
         Add(qryDadosVAL_ABRL.Value,´ABR´,clGreen);
         Add(qryDadosVAL_MAIO.Value,´MAI´,clGreen);
         Add(qryDadosVAL_JUNH.Value,´JUN´,clGreen);
         Add(qryDadosVAL_JULH.Value,´JUL´,clGreen);
         Add(qryDadosVAL_AGOS.Value,´AGO´,clGreen);
         Add(qryDadosVAL_STMB.Value,´SET´,clGreen);
         Add(qryDadosVAL_OUTB.Value,´OUT´,clGreen);
         Add(qryDadosVAL_NOVB.Value,´NOV´,clGreen);
         Add(qryDadosVAL_DZBR.Value,´DEZ´,clGreen);
      end;
   with QRChart1.Chart.Series[1] do
      begin
         Clear;
         for i:=1 to 12 do
            Add(qryIndicVAL_META.Value,QRChart1.Chart.Series[0].XLabel[i-1],clBlack);
         Title:=qryIndicVAL_META.AsString;
      end;
end;

procedure TfrmRelIndDesp.qryIndicAfterScroll(DataSet: TDataSet);
begin
   qryDados.Close;
   qryDados.Prepare;
   qryDados.Open;
end;

procedure TfrmRelIndDesp.qryDadosCalcFields(DataSet: TDataSet);
var sName,sMask:string;
begin
  inherited;
  if not qryTipIndic.Active then
     exit;
  if not qryTipIndic.Locate(´COD_TIPO_IDCD´,qryIndicCOD_TIPO_IDCD.Value,[]) then
     exit;
  //
  case qryDadosNUM_PARM.Value of
     1:begin
          sName:=qryTipIndicDES_PARA_1.Value;
          sMask:=qryTipIndicMSK_PARA_1.Value;
       end;
     2:begin
          sName:=qryTipIndicDES_PARA_2.Value;
          sMask:=qryTipIndicMSK_PARA_2.Value;
       end;
     3:begin
          sName:=qryTipIndicDES_PARA_3.Value;
          sMask:=qryTipIndicMSK_PARA_3.Value;
       end;
     4:begin
          sName:=qryTipIndicDES_PARA_4.Value;
          sMask:=qryTipIndicMSK_PARA_4.Value;
       end;
     5:begin
          sName:=qryTipIndicDES_PARA_5.Value;
          sMask:=qryTipIndicMSK_PARA_5.Value;
       end;
     6:begin
          sName:=qryTipIndicDES_RSLT.Value;
          sMask:=qryTipIndicMSK_RSLT.Value;
       end;
  end;
  //
  qryDadosParam.ReadOnly:=false;
  qryDadosParam.Value:=sName;
  qryDadosParam.ReadOnly:=true;
  qryDadosMask.Value:=sMask;
end;

procedure TfrmRelIndDesp.qryDadosFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
  if not qryTipIndic.Active then
     exit;
  if not qryTipIndic.Locate(´COD_TIPO_IDCD´,qryIndicCOD_TIPO_IDCD.Value,[]) then
     exit;
  //
  case qryDadosNUM_PARM.Value of
     1:begin
          Accept:=(qryTipIndicDES_PARA_1.Value <> ´´);
       end;
     2:begin
          Accept:=(qryTipIndicDES_PARA_2.Value <> ´´);
       end;
     3:begin
          Accept:=(qryTipIndicDES_PARA_3.Value <> ´´);
       end;
     4:begin
          Accept:=(qryTipIndicDES_PARA_4.Value <> ´´);
       end;
     5:begin
          Accept:=(qryTipIndicDES_PARA_5.Value <> ´´);
       end;
     6:begin
          Accept:=(qryTipIndicDES_RSLT.Value <> ´´);
       end;
  end;
end;

procedure TfrmRelIndDesp.qryDadosVAL_JANRGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);
begin
  Text:=FormatFloat(qryDadosMask.Value,Sender.AsFloat);
end;

procedure TfrmRelIndDesp.qryIndicCalcFields(DataSet: TDataSet);
begin
  qryIndicIndCliData.Value:=qryIndicDES_IDCD.Value+´ ´+
                           qryIndicCliente.Value+´ - ´+
                           FormatDateTime(´mmm/yyyy´,qryIndicDAT_IDCD.Value);
end;

end.



Programalista

Programalista

Curtidas 0

Respostas

Marcelo Saviski

Marcelo Saviski

04/04/2005

Bom, acho que é só mudar ali naquelas linhas:

[color=green:8e7ad8f892][i:8e7ad8f892]Add(qrydadosVAL_JANR.Value,´JAN´,clGreen); [/i:8e7ad8f892][/color:8e7ad8f892]

faça assim, antes do:
[color=green:8e7ad8f892][i:8e7ad8f892]var i:integer; [/i:8e7ad8f892][/color:8e7ad8f892]

declare isso:
const
  Cores: array[Boolean] of TColor = (clGreen, clRed);




e nas linhas troque por:

Add(qrydadosVAL_JANR.Value,´JAN´, Cores[qrydadosVAL_JANR.Value < ValorMeta]); 


ao invés de [b:8e7ad8f892][i:8e7ad8f892]clGreen[/i:8e7ad8f892][/b:8e7ad8f892], troque por
[b:8e7ad8f892]Cores[qrydadosVAL_[u:8e7ad8f892]MES[/u:8e7ad8f892].Value < ValorMeta][/b:8e7ad8f892]


GOSTEI 0
POSTAR