• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Need Graphs Bar & Lined Urgently!

hi, I would like to make a graph, could anyone show examples of making a bar and lined graphs.


like, for X/Y, a function could be 'Place(X,Y);' X is the enterd number of across row, Y is the result.


could you please provide Code & links, if your just gonna post links you will get less points, unless the link is good and meets the above function.

Sal.
0
SaLz
Asked:
SaLz
  • 9
  • 7
1 Solution
 
pcsentinelCommented:
I presume theres some reason you dont want to use the standard delphi components?

Do you want to draw a graph to a screen canvas?

Please provide more info

regards
0
 
SaLzAuthor Commented:
just to have a graph layout, and pin the graph with bars & lines. with a function like Place(X,Y);

if you know how to work the "standard delphi components" then please tell me below with an example of pin pointing a graph Bar & Line.

Sal.
0
 
geobulCommented:
Hi,

Have you tried TChart component? Drop one on a form (from 'Additional' tab), and one button. Open TChart.SeriesList property editor and add one series of type 'Line'. Go to 3D tab and uncheck '3 Dimensions' check box. Use the following code just for example (you'll actually add the series values yourself):

procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
  with Chart1.Series[0] do begin
    for i := 1 to 50 do
      Add(i mod 7, IntToStr(i), clRed); // add your values here
  end;
end;

Run the project and press the button.

Regards, Geo
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
SaLzAuthor Commented:
I've done that, but when I add more entrys it starts squashing the graph, how could I have like show a max of around 30 and it will display that and move just like the CPU usage in the Task Manager of Windows XP.
0
 
SaLzAuthor Commented:
there is also a white panel with numbers on the right how do I get rid of that?
0
 
SaLzAuthor Commented:
I've unticked the legend for the right panel.

how do I stop it squash the graph and have it free flowing at at a set display of like 30 or 50 entrys? new entry comes and the old disapears.
0
 
geobulCommented:
Hi,

For that white panel open SeriesList property, select the series, goto Legend tab and uncheck Visible.

For moving the graph from right to left:

const
  maxvv = 10;

var
  Form1: TForm1;
  vv: integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
  vv := 1;
  with Chart1.Series[0] do begin
    for i := 1 to maxvv do begin
      Add(vv mod 7, IntToStr(vv), clRed);
      vv := vv + 1;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
  // shift all values to left
  for i := 0 to maxvv - 2 do
    Chart1.Series[0].YValues.Value[i] := Chart1.Series[0].YValues.Value[i+1];
  // add the new value
  Chart1.Series[0].YValues.Value[maxvv - 1] := vv mod 7;
  Chart1.Repaint;
  vv := vv + 1;
end;

First press button1 once to load 10 values to the chart. Then press Button2 several times and see what's happening.

Regards, Geo
0
 
geobulCommented:
Perhaps you'd like to move the labels also. I forgot about them:

procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
  // shift all values and labels to left
  for i := 0 to maxvv - 2 do begin
    Chart1.Series[0].YValues.Value[i] := Chart1.Series[0].YValues.Value[i+1];
    Chart1.Series[0].XLabel[i] := Chart1.Series[0].XLabel[i+1];
  end;
  // add the new value
  Chart1.Series[0].YValues.Value[maxvv - 1] := vv mod 7;
  Chart1.Series[0].XLabel[maxvv - 1] := IntToStr(vv);
  Chart1.Repaint;
  vv := vv + 1;
end;

Regards, Geo
0
 
SaLzAuthor Commented:
is there no other way that swapping between button 1 and button 2?
0
 
SaLzAuthor Commented:
like it hits 50 entrys and then it will delete the old and will keep shifting with each entry?
0
 
SaLzAuthor Commented:
you know at the top of the graph at the pin point, is there anyway of knowing what the Number is when you hover your mouse over it?

or any other graph components if the TChart doesn't support it?
0
 
geobulCommented:
I think that's what you want:

const
  maxvv = 50; // there will be 50 points

var
  Form1: TForm1;
  vv: integer;

implementation

{$R *.DFM}

// fill 50 empty points
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
  with Chart1.Series[0] do begin
    for i := 1 to maxvv do begin
      Add(0, ' ', clBtnFace);
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
  // shift all values and labels to left
  for i := 0 to maxvv - 2 do begin
    Chart1.Series[0].YValues.Value[i] := Chart1.Series[0].YValues.Value[i+1];
    Chart1.Series[0].XLabel[i] := Chart1.Series[0].XLabel[i+1];
    // color the non-empty points
    if Chart1.Series[0].XLabel[i] <> ' ' then Chart1.Series[0].ValueColor[i] := clRed;
  end;
  // add the new value
  Chart1.Series[0].YValues.Value[maxvv - 1] := vv mod 7;
  Chart1.Series[0].XLabel[maxvv - 1] := IntToStr(vv);
  Chart1.Repaint;
  vv := vv + 1;
end;

Regards, Geo
0
 
SaLzAuthor Commented:
thats smashing :D it pins the graph in both Bar & lines & it progressive.

you know when the graph is layed out, I have no clue what the pins result numbers are, just a estimate of what the pin is located at, is there anyway to hover your mouse over or display the results above the pin?
0
 
geobulCommented:
Hi,

Add two labels on the form and write TChart.OnMouseMove event like:

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  XValue, YValue: double;
begin
  Chart1.Series[0].GetCursorValues(XValue, YValue);
  Label1.Caption := FloatToStr(XValue);
  Label2.Caption := FloatToStr(YValue);
end;

Regards, Geo
0
 
geobulCommented:
You need the Y value only. So, remove
Label2.Caption := FloatToStr(YValue);
line from the above.
0
 
SaLzAuthor Commented:
thats perfect, does everything that is needed, its got Bar & Line Graph, it Pins them with X,Y, its got Progressive where you can set the lengh before it passes on, you can move your mouse over the line and it tells you the number and with the Panel on the right it gives you the correct number and thats progressive.

button 1 is now on form create and button 2 are the entrys.

this is perfect, just what I wanted, thxs geobul :D

Sal.
0
 
geobulCommented:
You are welcome :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now