|
Registriert seit: 19. Sep 2013 Ort: Braunschweig 204 Beiträge Delphi 6 Professional |
#1
Hallo Ihr Lieben,
ich benötige nochmal eure Hilfe, um endlich mit meinem Histographen abschließen zu können. Wie mache ich das jetzt, dass er innerhalb meines Anzeigebereichs, von links nach rechts und immer, in der Mitte der Y-Achse, einen Datensatz, den er Extern bekommt, als Sinus anzeigt ???
Delphi-Quellcode:
function mysin(const X: Extended):Extended; // Wrapper-Funktion, benötigt für Delphi 6 um Sinus-Funktion implementieren zu können
begin Result := sin(x); end; function THixHistoGraph.CalculatePointView // Berechnung der Punkte für die Funktionsdarstellung (AFunc: TFxFunction; const ARect: TRect; x0, y0, dx, dy: Extended): TPointDynArray; var x, y: Extended; i : integer; begin // für jede Spalte einen Punkt SetLength(Result, ARect.Right - ARect.Left +1); // Punkte berechnen x := 0; for i := Low(Result) to High(Result) do begin y := AFunc(x); y := -y; // Canvas Nullpunkt obere linke Ecke mit Y- Achse nach unten !!! y := y0 + y; // oberen Rand Addieren y := y / dy; // Skalieren Result[i].x := ARect.Left +1; Result[i].Y := ARect.Top + Round(y) + Round(y); // runden x := x + dx; end; // nächster Punkt end; //////////////////////////////////////////////////////////////////////////////// // // // Zeichnen // // // //////////////////////////////////////////////////////////////////////////////// procedure THixHistoGraph.DrawComponent; var ComponentBackround : TRect; // zeichnet Komponente HistoBackround : TRect; // zeichnet die Darstellungsfläche der Komponente P : TPointDynArray; X0, Y0, dx, dy :Real; begin if FBorderstyle = bsSingle then // mit 3D-Rahmen begin inherited; if (Parent = NIL) or not visible then Exit; begin ComponentBackround := Rect(0, 0, Width, Height); // Koponentenhintergrund end; Canvas.Brush.Color := FColor; Canvas.Pen.Color := FColor; Canvas.Pen.Style := psSolid; Canvas.FillRect(ComponentBackround); Frame3D(Canvas, ComponentBackround, clBtnHighlight, clBtnShadow, 1); // 3D Rahmen mit der Breite von 1 für Komponentenhintergrund begin HistoBackround := Rect(FGapLeft, // Hintergrund der Darstellungsfläche FGapTop, Width - FGapRight, Height - FGapBottom + 2); end; Canvas.Brush.Color := FHistoBkColor; Canvas.Pen.Color := FHistoBkColor; Canvas.FillRect(HistoBackround); Frame3D(Canvas, HistoBackround, clBtnShadow, clBtnHighlight, 1); begin // Zeichnet Messdaten InflateRect(HistoBackround, -1, -1); // Darstellung im Hinergrund ohne Ränder X0 := 0; Y0 := 3; dx := 0.05; dy := 0.05; P := CalculatePointView(mysin, HistoBackround, X0, Y0, dx, dy); // berechnet Funktion aus Messdaten end; Canvas.Brush.Color := cllime; Canvas.Pen.Color := cllime; DrawPointView(Canvas, HistoBackround, P); end; end; procedure THixHistoGraph.Resize; // überschreibt die gesetzten Werte aus SubKomponenten, um die Skalen positionieren zu können begin inherited; //FXScale.BkColor := clyellow; // zum Testen FXScale.Left := 1; FXScale.Width := Width - 2; FXScale.XGapLeft := FGapLeft; FXScale.XGapRight := FGapRight; FXScale.Top := Height - FGapBottom + 2; //FYScale.BkColor := clSkyBlue; // zum Testen FYScale.Top := 1; FYScale.YGapTop := GapTop; FYScale.YGapBottom := FXScale.GridHeight; FYScale.Left := 1; FYScale.Height := Height - FGapBottom + FXScale.GridHeight; FYScale.Width := FGapLeft - 1; end; procedure THixHistoGraph.DrawGrid; // zeichnet Hintergrundraster var Value : Real; begin inherited; Canvas.Pen.Color := FBKGridColor; Canvas.Brush.Color := FBKGridColor; Canvas.Pen.Style := FGridLineStyle; begin if FGridVisible = grdVer then // Hintergrundraster in Y-Richtung begin inherited; Value := (FXScale.ValMin); while (Value <= FXScale.ValMax) do begin inherited; Canvas.MoveTo((FGapLeft + 1) + round((Width - 2 - (FGapLeft + FGapRight)) * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))), (Height - FGapBottom)); Canvas.LineTo((FGapLeft + 1) + round((ClientWidth - 2 - (FGapRight + FGapLeft)) * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))), FGapTop); Value := (Value + FXScale.ValGap); end; end; if FGridVisible = grdHor then // Hintergrundraster in X-Richtung begin inherited; Value := (FYScale.ValMin); while (Value <= FYScale.ValMax) do begin inherited; Canvas.MoveTo(FGapLeft, FGapTop + 1 + round((ClientHeight - (FGapBottom + FGapTop)) * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin)))); Canvas.LineTo(Width - FGapRight, FGapTop + 1 + round((ClientHeight - (FGapBottom + FGapTop)) * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin)))); Value := (Value + abs(FYScale.ValGap)) ; end; end; if FGridVisible = grdBoth then // Hintergrundraster in X und Y-Richtung begin inherited; Value := (FXScale.ValMin); while (Value <= FXScale.ValMax) do begin inherited; Canvas.MoveTo((FGapLeft + 1) + round((Width - 2 - (FGapLeft + FGapRight)) * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))), (Height - FGapBottom)); Canvas.LineTo((FGapLeft + 1) + round((ClientWidth - 2 - (FGapRight + FGapLeft)) * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))), FGapTop); Value := (Value + FXScale.ValGap); end; Value := (FYScale.ValMin); while (Value <= FYScale.ValMax) do begin inherited; Canvas.MoveTo(FGapLeft, FGapTop + 1 + round((ClientHeight - (FGapBottom + FGapTop)) * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin)))); Canvas.LineTo(Width - FGapRight, FGapTop + 1 + round((ClientHeight - (FGapBottom + FGapTop)) * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin)))); Value := (Value + abs(FYScale.ValGap)) ; end; end; end; end; procedure THixHistoGraph.DrawPointView (ACanvas: TCanvas; const ARect: TRect; const APoints : TPointDynArray); var h : Thandle; begin h:= SaveDC(ACanvas.Handle); try IntersectClipRect(ACanvas.Handle, ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); // Zeichenfläche einschränken Polyline(ACanvas.Handle, APoints[0], Length(APoints)); finally RestoreDC(ACanvas.Handle, h); end; end; procedure THixHistoGraph.Paint; begin inherited; DrawComponent; DrawGrid; end;
Christian
|
![]() |
Ansicht |
![]() |
![]() |
![]() |
ForumregelnEs ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus. Trackbacks are an
Pingbacks are an
Refbacks are aus
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
![]() |
![]() |