String sql,elemento="Aserraderos",nelemento,coef,fecha,ctotal,cprom;
double coeficiente,suma=0,promedio,poblacion;
// TColor color_inicial=clNavy;
TColor colores[8]={clInactiveCaption,clBlue,clGreen,clMaroon,clOlive,clFuchsia,clLime};
int i,n,aleatorio;
sql="SELECT Elemento, Cantidad FROM configuracion WHERE ELEMENTO LIKE '"+elemento+"'";
Query1->SQL->Clear();
Query1->SQL->Add(sql);
Query1->Open();
n=Query1->FieldByName("Cantidad")->AsInteger;
Query1->Close();
StringGrid2->RowCount=n+1;
fecha=StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row];
StringGrid2->Font->Color=clMaroon;
poblacion=n;
Chart1->Series[0]->Clear();
// Chart1->Series[0]->AddXY(1,25,"One",clBlue);
for(i=1;i<n+1;i++)
{
nelemento=i;
sql="SELECT Coeficiente FROM coeficientes WHERE Fecha LIKE '"+fecha+"' AND Aserradero="+nelemento;
Query1->Close();
Query1->SQL->Clear();
Query1->SQL->Add(sql);
Query1->Open();
if(!Query1->IsEmpty())
{
coeficiente=Query1->FieldByName("Coeficiente")->AsFloat;
if(coeficiente==0)
coef="";
else
coef=FormatFloat("0.00",coeficiente)+'%';
}
else
{
coeficiente=0;
coef="";
}
suma+=coeficiente;
ctotal=suma;
StringGrid2->Cells[0][i]=nelemento;
StringGrid2->Cells[1][i]=coef;
aleatorio=rand()%7;
Chart1->Series[0]->AddXY(i,coeficiente,i,colores[aleatorio]);
}
promedio=suma/poblacion;
cprom=promedio;