PDA

Ver la Versión Completa : Cargar datos separados por comas en un Tchart


farute
25-01-2018, 11:11:18
Pues eso, como podría hacer para cargar por ejemplo esta fuente de datos en un Tchart
que en la X me salga el primer campo Time y en la Y el segundo campo TemperatureC
https://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IVILLAQU3&day=25&month=1&year=2018&graphspan=day&format=1


muchas gracias

ecfisa
26-01-2018, 00:22:56
Hola.

Por lo que entiendo deseas que aparezca la fecha/hora sobre el eje de las absisas y la temperatura en el eje de las ordenadas. Si es así, podes hacer:

...
implementation

procedure TForm1.FormCreate(Sender: TObject);
var
stFile, stComa : TStrings;
aux : Char;
i : Integer;
begin
Chart1.BottomAxis.LabelsAngle := 90; // vertical;
stFile := TStringList.Create;
aux := DecimalSeparator;
DecimalSeparator := '.';
try
stFile.LoadFromFile('WUNDERGROUND.TXT'); //(Archivo copia fiel de los datos de tu enlace)
for i := 1 to stFile.Count - 1 do
begin
stComa := TStringList.Create;
try
ExtractStrings([','], [], PChar(stFile[i]), stComa);
Chart1.Series[0].Add(StrToFloatDef(stComa[1],0), stComa[0]);
finally
stComa.Free;
end;
end;
finally
stFile.Free;
DecimalSeparator := aux;
end;
end;
...


Salida:
https://s18.postimg.org/5ly7u04ft/farute.png

Saludos :)

farute
26-01-2018, 09:44:04
Muchas gracias, funciona perfecto. ^\||/

por cierto lo de decimalseparator he quitado esas líneas porque en los ultimos delphis no lo reconoce,
como se pone para que vaya?

farute
26-01-2018, 10:47:49
ahora me surge otro problema si yo copio el texto que sale aquí en un fichero de texto lo pilla sin problemas
https://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IVILLAQU3&day=25&month=1&year=2018&graphspan=day&format=1

pero si yo descargo ese fichero con IdHTTP

con


uses IdHTTP;

var S: string;
begin
IdHTTP: TIdHTTP;

IdHTTP := TIdHTTP.Create(nil);
try
S := IdHTTP.Get('https://espanol.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IVILLAQU3&day=25&month=1&year=2018&graphspan=day&format=1');
finally
IdHTTP.Free;
end;
end;

el fichero resultante me sale con saltos de linea y <br> y no lo pilla

farute
26-01-2018, 13:07:42
vale con esto ya he consegido quitar los saltos de linea
s:= s.Replace(#10+'<br>','');