Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

draw unconnected points in line series of tchart

Posted on 2014-07-15
21
Medium Priority
?
957 Views
Last Modified: 2014-07-24
Is it possible to draw unconnected points in a line series of a TChart ? Can I turn off the automatic connecting of points drawn using AddXY ?
0
Comment
Question by:ChLa
  • 12
  • 9
21 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 40198590
Why not using a different seriestype like TPointSeries????

You can change at runtime with TChart function ChangeSeriesTyp(..)
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40198592
You may also use the trick to set series line color to background color...
0
 

Author Comment

by:ChLa
ID: 40200012
I think the reason I never used the point series is because the picture of it doesn't look anything like what I am trying to do. I deleted the three line series and replaced them with point series. It seems to be working except for two things. One of the lines is still connecting to itself. So I zoomed way in to see the points. But I see zigzag (stairstep) lines, no points. What is happening here ? What is making the point series like a line series ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Thommy
ID: 40201436
Can you provide a screenshot of the zigzag lines?
0
 

Author Comment

by:ChLa
ID: 40202666
Here is a picture. On the left you see the chart now using point series, after drawing the three lines. These were plotted using PlotXY, On the right you see I have zoomed into the chart to show the lines very close. I was expecting to see dots, but instead I see zigzag lines.
Twosmallcharts.jpg
0
 

Author Comment

by:ChLa
ID: 40202697
In this second image of nearly the same pan, but CCW, you see a line has been added connecting the end of the first segment to the start of the fifth segment, for the center line only. Also you may notice the third main segment of the center line isn't drawn after the line returns on the right (after going off to the left). This is almost certainly because of an AddNullXY I haven't yet removed since changing to point series from line series. I wonder if more lines will appear when I remove all the addnullXY's ?
0
 

Author Comment

by:ChLa
ID: 40202703
0
 

Author Comment

by:ChLa
ID: 40207837
I have done a further experiment. I started a new project. I put a TChart on the form. I put a panel on the form. I added a point series to the chart. I made adjustments to the chart so it looks like the other chart shown above. I added an onclick event to the panel "Chart1.Series[1].AddXY(20, 20, '', clRed); ".
When I click on the panel I get this message: Mdiapp Access Violation at address 40340000. Read of address 40340000".
What is going on here ?
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40208321
Your problem sounds really, very strange!!!

Can you please provide a small example project, so that I can get this issue reproduced?

Or better, you may consult Steema TeeChart support...
Steema Support Central
0
 

Author Comment

by:ChLa
ID: 40209731
I agree it sounds very wierd. IN fact, I was thinking my installation of TChart that came with Delphi 2010 is corrupted. Last night I remembered I have an installation of Delphi 2010 on another computer. I repeated the above experiment precisely and got the same results, as if AddXY isn't a command that can be used with a point series. I will try to attach the test project. I am not sure which files to include. Let me know. I will attach the executable now. I will also attach the .pas file.
0
 

Author Comment

by:ChLa
ID: 40209742
Here is the .pas file
ChartTest2.pas
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40210832
Please also attach the .dpr and .dfm files...
0
 

Author Comment

by:ChLa
ID: 40212996
Here are those two files
ChartTest2.dfm
MDIAPP.dpr
0
 
LVL 19

Accepted Solution

by:
Thommy earned 2000 total points
ID: 40214303
The access violation occurrs because you tried to reference a point series by index, that does not exist.
Series indexes always start with '0' not with '1!!!
Because you have created just one point series at design time, you have to reference it with index '0' as follows:
Chart1.Series[0].AddXY(20, 20, '', clRed);

After having corrected this error, I tried out AddXY(..) in relation with point series.
I cannot identify any problems and there are no zigzag lines either!

So please try yourself, if you can reproduce your problem with that demo app and tell me how you did...
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40214324
Can you please post the part of your code, where you are dynamically drawing the lines?
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40214348
In your previous post ID: 40202666 you mention, that "the three lines are plotted using PlotXY"

Could you please explain that?

I've never heard of a function PlotXY in TChart!!!
0
 

Author Comment

by:ChLa
ID: 40215325
I'm sorry. I used AddXY. I misremembered it as PlotXY because that is what it means to me.
0
 

Author Comment

by:ChLa
ID: 40215370
Okay, you are right about it being series zero, not one. I actually thought of this a few nights ago. But when I looked and saw the series was numberes one and not zero, I dismissed the idea. That solves this problem and allows me to do some experimenting with point series. Still, it doesn't solve the mysteries of the other question, about plotted points connecting together, and such. For some reason I stopped getting answers to the other question. I suppose I need to have simpler smaller questions.
0
 

Author Comment

by:ChLa
ID: 40215400
Okay, you asked for some of my code for drawing lines. Here is my code for the main segment, the third segement.

// ***FullSpeedPan************************************************************************

  // Chart1.Series[5].AddNullXY(PLastPlotCentPntX,PLastPlotCentPntY);

  TimesThroughLoop := 0;
  Days := 0;
  LastDays := 0;

  while TimesThroughLoop < FullSpeedPanFrames do
  Begin
    TimesThroughLoop := TimesThroughLoop + 1;
    TestInt := TestInt + 1;
    If PanDirection = 0 then
      RunningDegrees := RunningDegrees + (PanStepsFrame * PanDegreesStep)
    else
      RunningDegrees := RunningDegrees - (PanStepsFrame * PanDegreesStep);
    RunningS := (RunningS + FrameIntervalTotalSec);
    if RunningS > 59 then
    Begin
      RunningM := RunningM + (RunningS div 60);
      RunningS := (RunningS mod 60);
    End;
    If RunningM > 59 then
    Begin
      RunningH := RunningH + (RunningM div 60);
      RunningM := (RunningM mod 60);
    End;

    DecimalTime := (RunningH + (RunningM / 60));

    While DecimalTime > 24 do // if we go over 24 hours
    begin
      Days := Days + 1;
      DecimalTime := DecimalTime - 24; // fix hours
      if FSPLOnlyOnceFlag = 0 then
      begin
        FSPLOnlyOnceFlag := 1;
        Chart1.Series[5].AddNullXY(PLastPlotCentPntXL, PLastPlotCentPntYL);
      end;

      Chart1.Series[4].AddNullXY(PLastPlotCentPntXR, PLastPlotCentPntYR);
      Chart1.Series[3].AddNullXY(PLastPlotCentPntXC, PLastPlotCentPntYC);
      //Memo1.Lines.Add(IntToStr(Days));
    end;

    If Days <> LastDays then // this prevents connecting end of one line to start of next when hrs go over repeatedly
        begin
        Chart1.Series[5].AddNullXY(PLastPlotCentPntXL, PLastPlotCentPntYL);
        IterationTest := IterationTest + 1;
        Memo1.Lines.Add(IntToStr(Days) + ' Days');
        end;

    AdjustedRunningDeg := RunningDegrees;
    if RunningDegrees < 0 then // this fixes running degrees if it goes under
    begin
      AdjustedRunningDeg := RunningDegrees + 360;
      Chart1.Series[3].AddNullXY(PLastPlotCentPntXC, PLastPlotCentPntYC);
    end;
    if RunningDegrees > 360 then // this fixes running degrees if it goes over
    begin
      AdjustedRunningDeg := RunningDegrees - 360;
      Chart1.Series[3].AddNullXY(PLastPlotCentPntXC, PLastPlotCentPntYC);
    end;

    // Chart1.Series[4].AddNullXY(AdjustedRunningDeg,DecimalTime);

    Chart1.Series[3].AddXY(AdjustedRunningDeg, DecimalTime, '', clBlack);

    Chart1.Series[3].AddNullXY(AdjustedRunningDeg, DecimalTime);

    PLastPlotCentPntXC := AdjustedRunningDeg;
    PLastPlotCentPntYC := DecimalTime;

    AdjustedRunningDeg := RunningDegrees;
    if (RunningDegrees - (LensFOV / 2)) < 0 then // this fixes running degrees if it goes under
    begin
      AdjustedRunningDeg := RunningDegrees + 360;
      if FSPLOnlyOnceFlag = 0 then // this doesn't seem to be helping
      begin
        FSPLOnlyOnceFlag := 1;
        Chart1.Series[5].AddNullXY(PLastPlotCentPntXL, PLastPlotCentPntYL);
      end;

      // Chart1.Series[5].AddNullXY(PLastPlotCentPntXL,PLastPlotCentPntYL);
    end;
    if (RunningDegrees - (LensFOV / 2)) > 360 then     // this fixes running degrees if it goes over
    begin
      AdjustedRunningDeg := RunningDegrees - 360;

      // if FSPLOnlyOnceFlag = 0 then           //not sure this is helping
      // FSPLOnlyOnceFlag := 1;
      // Chart1.Series[5].AddNullXY(PLastPlotCentPntXL,PLastPlotCentPntYL);
      // end;

      // Chart1.Series[5].AddNullXY(PLastPlotCentPntXL,PLastPlotCentPntYL);
    end;

    Chart1.Series[5].AddXY(AdjustedRunningDeg - (LensFOV / 2), DecimalTime, '', clBlue);

    if (PanDirection = 1) and (Days <> LastDays) then  // this prevents connecting end of one line to start of next when hrs go over repeatedly during CCW
      begin
      Chart1.Series[5].AddNullXY((AdjustedRunningDeg - (LensFOV / 2)),DecimalTime);
      //Chart1.Series[4].AddNullXY((AdjustedRunningDeg + (LensFOV / 2)),DecimalTime);
      //Memo1.Lines.Add('if both ifs');
      end;

    //Chart1.Series[5].AddNullXY(PLastPlotCentPntXL, PLastPlotCentPntYL);       //this preventx left line from being drawn


    PLastPlotCentPntXL := AdjustedRunningDeg - (LensFOV / 2);
    PLastPlotCentPntYL := DecimalTime;

    if FirstPointOnceOnlyFlagL = 0 then
    begin
      FirstPointXL := PLastPlotCentPntXL;
      FirstPointYL := DecimalTime;
      FirstPointOnceOnlyFlagL := 1;
    end;

    Chart1.Series[5].AddNullXY(FirstPointXL,FirstPointYL);
  //  Chart1.Series[4].AddNullXY(FirstPointXR,FirstPointYR);

    // Chart1.Series[5].AddNullXY(AdjustedRunningDeg - (LensFOV / 2), DecimalTime);

    AdjustedRunningDeg := RunningDegrees;
    if (RunningDegrees + (LensFOV / 2)) < 0 then // this fixes running degrees if it goes under
    begin
      AdjustedRunningDeg := RunningDegrees + 360;
      Chart1.Series[4].AddNullXY(PLastPlotCentPntXR, PLastPlotCentPntYR);

    end;
    if (RunningDegrees + (LensFOV / 2)) > 360 then
    // this fixes running degrees if it goes over
    begin
      AdjustedRunningDeg := RunningDegrees - 360;
      Chart1.Series[4].AddNullXY(PLastPlotCentPntXR, PLastPlotCentPntYR);

    end;

    Chart1.Series[4].AddXY(AdjustedRunningDeg + (LensFOV / 2), DecimalTime, '',
      clGreen);

    PLastPlotCentPntXR := AdjustedRunningDeg + (LensFOV / 2);
    PLastPlotCentPntYR := DecimalTime;

    If FirstPointOnceOnlyFlagR = 0 then
    begin
      FirstPointXR := PLastPlotCentPntXR;
      FirstPointYR := DecimalTime;
      FirstPointOnceOnlyFlagR := 1;
    end;

    Chart1.Series[4].AddNullXY(FirstPointXR,FirstPointYR);

    // Memo1.Lines.Add('B =  ' + FloatToStr(CHSeriesB) + '   A =  ' + FloatToStr(CHSeriesA) + '   C =  ' + FloatToStr(CHSeriesC) + '    SL ' + FloatToStr(Edit3.SelLength) );
    // Chart1.Repaint;
    // Chart1.Refresh;
    If TestInt = GraphSpeed then // redraws graph during full speed ramp loop to make it animated
    Begin
      Chart1.Update;
      TestInt := 0;
    End;

    LastDays := Days;
    Days := 0;

    // Chart1.Invalidate;
  End;
  // Series3.AddNull('');
  Panel71.Caption := FloatToStr(RunningH) + ':' + FormatFloat('00', RunningM)
    + ':' + FormatFloat('00', RunningS);

  Chart1.Series[5].AddNullXY(PLastPlotCentPntXL, PLastPlotCentPntYL);
  Chart1.Series[4].AddNullXY(PLastPlotCentPntXR, PLastPlotCentPntYR);
  Chart1.Series[3].AddNullXY(PLastPlotCentPntXC, PLastPlotCentPntYC);

  // ***RampDown*********************************************************************************************

You can see all the work I had to do with addnulls to stop connecting lines from being drawn. It occurs to me that the problems I have been having could all be related to my using the series number, instead of the series number minus one. This alone may solve my problems with TCharts. What I have been thinking is that I should remove the existing chart and relace it with a new one. Then I would add one or three point series, and change all the ADDXY's to the new series number(s). If all this works, I wonder this. Can I do what i want with only one series ? I was using different series before to help avoid connecting lines, and to have different colors for each line. Now I suspect I don't need to do that. What do you think ?
0
 
LVL 19

Expert Comment

by:Thommy
ID: 40216929
Yes, I think you can do it with just one series that.

You can set different colors for the value markers as follows:
Chart1.Series[0].ValueColor[1]:=clGreen;
0
 

Author Closing Comment

by:ChLa
ID: 40218266
At this point I think most likely all the problems I have been having with TCharts come from trying to access series by their indicated number instead of that number minus one. So I am closing this question and the other, and awarding points to Thommy, once again. Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question