Chart formats strange at runtime after dynamic code

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Fri Aug 26, 2011 6:00 pm

Please could someone help clarify this for me ASAP (I'm in the middle of finalizing a project, need the graphs to format better).

Scenario:

I'm adding values to the TeeChart dynamically (including custom axes, series, and series values).
I get the desired results with the exception of the chart not formatting nicely (like it does when it's set up via the wizard).

I'm sure it's just a matter of refreshing the template or something like that, I just don't know how!

Here are my examples:

This is how the original graph looks like
teechart_good.JPG
teechart_good.JPG (43.22 KiB) Viewed 10243 times
This is how my new graph looks like
teechart_bad.JPG
teechart_bad.JPG (62.77 KiB) Viewed 10232 times
My main concern at this point is the following:
I need my new graph to only show bottom axis label for where there are records (just like the first one)
I need the graph to show xy axis labels where there are records (just like the first one)
I need the left margin to adjust automatically to show the full reading labels and axis titles (just like the first one)

Please advise, I need this ASAP since we're supposed to release soon!

FYI: here is some of the sample code, just snippets not the entire function (I don't think you really need it but just so you know how I'm doing this):

fraPCTGraphByAnalysis.chtGraph.CustomAxes.Clear;
fraPCTGraphByAnalysis.chtGraph.RemoveAllSeries;

Adding the custom axes:

Code: Select all

         sgSeriesGroup := fraPCTGraphByAnalysis.chtGraph.SeriesList.AddGroup(slProductTypes[i]);
         caAxis := fraPCTGraphByAnalysis.chtGraph.CustomAxes.Add as TChartAxis;
         caAxis.Title.Angle := 90;
         caAxis.Title.Caption := slProductTypes[i];
         caAxis.StartPosition := iAxesStart;
         caAxis.EndPosition := iAxesStart + iAxesSize;
         caAxis.AxisValuesFormat := '#0.000';
Adding the series:

Code: Select all

         for i2 := 0 to slChemicalComponents.Count - 1 do
         begin
            csSeries := TLineSeries.Create(self);
            csSeries.Pointer.Visible := true;
            csSeries.Pointer.Size := 2;
            csSeries.Title := slChemicalComponents[i2];
            csSeries.CustomVertAxis := caAxis;
            csSeries.XValues.DateTime := true;
            sgSeriesGroup.Add(csSeries);
            fraPCTGraphByAnalysis.chtGraph.AddSeries(csSeries);
         end;
Adding the values:

Code: Select all

         for i2 := 0 to Length(aReadingRecord) - 1 do
            //consider records that only belong to this Product group (for loop "i")
            if aReadingRecord[i2].sProduct = caAxis.Title.Caption then
            begin
               //get the series in the current Product group
               for i3 := 0 to sgSeriesGroup.Series.Count - 1 do
                  if aReadingRecord[i2].sSeries = sgSeriesGroup.Series[i3].Title then
                     sgSeriesGroup.Series[i3].AddXY(aReadingRecord[i2].dTestDate,aReadingRecord[i2].fReading);
            end;
         end;

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Mon Aug 29, 2011 3:10 pm

Of course I forgot to mention the version.

v8.01.10798 Win32

Can we please get some help with this issue?

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Yeray » Tue Aug 30, 2011 7:48 am

Hello,

Excuse us for the delayed reply.
Metegrity Inc. wrote:I need my new graph to only show bottom axis label for where there are records (just like the first one)
In the actual TeeChart there is a new axis LabelStyle, named talPointValue that would do it for you.
However, in v8 I'm afraid it doesn't exist. The easiest way to do it is to add your points with the labels and use talText LabelStyle. The label entered would be the string taken from the XValue datetime.
Metegrity Inc. wrote:I need the graph to show xy axis labels where there are records (just like the first one)
Isn't this the same than above? If not, please try to explain it again.
Metegrity Inc. wrote:I need the left margin to adjust automatically to show the full reading labels and axis titles (just like the first one)
The custom axes don't do it by default. But you always can add some LeftMargin considering the axis MaxLabelsWidth. Something as follows:

Code: Select all

  chtGraph.MarginUnits:=muPixels;
  chtGraph.MarginLeft:=caAxis.MaxLabelsWidth + caAxis.TickLength + 5;
And don't forget that the chart needs to be drawn for the MaxLabelsWidth to have a valid value. So call chtGraph.Draw before the above if necessary.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Tue Aug 30, 2011 1:56 pm

Thank you for the reply.
I will try the mentioned methods and will let you know if I have any further questions.

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Tue Aug 30, 2011 5:14 pm

Awesome, it's starting to look like a proper graph now :) (of course I got more tweaking to do).

One more thing though, I'm wondering if I can somehow expand the series coloring theme.
teechart_bad3.JPG
teechart_bad3.JPG (66.5 KiB) Viewed 10188 times
If you notice, after some of the series they stop having a color associated with them and they are all assigned to gray (ignore the repeated "black" series, that's just the downsizing of the .jpg image, but after the "white" H+ the gray color repeats).

How can I solve that problem?

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Yeray » Wed Aug 31, 2011 8:38 am

Hello,
Metegrity Inc. wrote:Awesome, it's starting to look like a proper graph now :) (of course I got more tweaking to do).
I hope so! :)
Metegrity Inc. wrote:One more thing though, I'm wondering if I can somehow expand the series coloring theme.
By default, the OperaPalette is used to color your series. This palette is an array of 12 colors. If you want, you can create your custom palette and/or make your series use that palette restarting from its first color after using its last color. Something like following:

Code: Select all

  for i:=0 to 30 do
    with Chart1.AddSeries(TPointSeries) do
    begin
      FillSampleValues(5);
      Color:=OperaPalette[i mod Length(OperaPalette)];
    end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Fri Sep 02, 2011 7:49 pm

Yeray wrote:Hello,
By default, the OperaPalette is used to color your series. This palette is an array of 12 colors. If you want, you can create your custom palette and/or make your series use that palette restarting from its first color after using its last color. Something like following:

Code: Select all

  for i:=0 to 30 do
    with Chart1.AddSeries(TPointSeries) do
    begin
      FillSampleValues(5);
      Color:=OperaPalette[i mod Length(OperaPalette)];
    end;
Wonderful, that helps!

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Tue Sep 06, 2011 8:27 pm

I am nearly ready to finalize the graph, but I do require some assistance with one rather annoying issue:
teechart_bad4.JPG
teechart_bad4.JPG (71.46 KiB) Viewed 10094 times
I highlighted which values are not showing on the grid/bottom axis.

The values are there but for some reason they don't always show on the axis. I need them to be there.
Is there a way I can force this to happen? I have the ShowAllLables enabled on the bottom axis (in the Chart wizard, not in code).

As I disable so of the Product Type (Gas, Condensate, Liquids) they values start appearing on the bottom axis, so I know the graph "knows" what they are!

For example if I disable Gas I can see ALL the labels for the Condensate axis but none of the Liquids axis labels, but when I only have the Liquids enabled I see all of it's labels.

Here is a stub of what the process of creating all of that stuff is:

First I make a list of the Product Types

Code: Select all

      with TdtmPLProductContentTesting(miDataModule) do
      begin
         SetLength(aReadingRecord, cdsGraph.RecordCount);
         i:=0;

         while not cdsGraph.Eof do
         begin
//DO STUFF HERE
            cdsGraph.Next;
         end;//while not cdsGraph.Eof do

         cdsGraph.First;
      end;//with TdtmPLProductContentTesting(miDataModule) do
Then we get into setting up the graph:

Code: Select all

      for i := 0 to slProductTypes.Count - 1 do
      begin

         //CREATE THE AXES HERE
         
         //CREATE THE SERIES LIST HERE
         for i2 := 0 to Length(aReadingRecord) - 1 do
            //consider records that only belong to this Produc group (for loop "i")
            if aReadingRecord[i2].sProduct = caAxis.Title.Caption then
               slSeries.Add(aReadingRecord[i2].sSeries);

         //add the series groups to the graph
         for i2 := 0 to slSeries.Count - 1 do
         begin
             //ADD THE LINE SERIES TO THE GRAPH IN HERE
         end;//for i2 := 0 to slChemicalComponents.Count - 1 do

         //attach values to the series
         for i2 := 0 to Length(aReadingRecord) - 1 do
            //consider records that only belong to this Product group (for loop "i")
            if aReadingRecord[i2].sProduct = caAxis.Title.Caption then
            begin
               //get the series in the current Product group
               for i3 := 0 to sgSeriesGroup.Series.Count - 1 do
                  if (aReadingRecord[i2].sSeries+' ('+
                     dtmLKLookup.ldsTLTranslationTable.Lookup('TRANSLATIONID',
                     slProductTypes[i],'FIELDLABEL')+')') = sgSeriesGroup.Series[i3].Title then
                  begin
                     sgSeriesGroup.Series[i3].AddXY(aReadingRecord[i2].dTestDate,
                        aReadingRecord[i2].fReading,
                        DateToStr(aReadingRecord[i2].dTestDate));
                  end;//if aReadingRecord[i2].sSeries = sgSeriesGroup.Series[i3].Title then
            end;//if aReadingRecord[i2].sProduct = caAxis.Title.Caption then
         end;//for i2 := 0 to Length(aReadingRecord) - 1 do
Please let me know if you need more of the code, or any other samples/questions.
I assume it has something to do with the fact that I go through and add the new series, then the values, right after the axis is created? Maybe?
I don't want to change the code if you may have an idea of what the issue could be.
Otherwise I suppose I could try to add values to the series in a loop outside of the main "Axes" loop. So make the axes, make the series, exist loops and then go through the list of series and add their values then...?

Thank you!

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart formats strange at runtime after dynamic code

Post by Sandra » Wed Sep 07, 2011 11:52 am

Hello Metegrity Inc,

I think that your problem is due you doesn't add labels for each point you have in the chart and leave the default labels in the bottom axis. I suggest a solution to arrange your labels, you only need use custom labels as do in next simple code, where is adding for each series points, a label:

Code: Select all

procedure TForm3.FormCreate(Sender: TObject);
var i,j:Integer;
myDate:TDateTime;
begin
Chart1.view3D:= false;
Series1.FillSampleValues(2);
Series2.FillSampleValues(3);
Series3.FillSampleValues(6);

Series1.Pointer.Visible:=true;
Series2.Pointer.Visible:=true;
Series3.Pointer.Visible:=true;

Series1.XValues.DateTime:=True;
Series2.XValues.DateTime:=True;
Series3.XValues.DateTime:=True;

Chart1.Legend.CheckBoxes:=True;
Chart1.Axes.Bottom.Items.Clear;

for i := 0 to Chart1.SeriesCount- 1 do
begin
For  j:=0 To Chart1[i].Count-1 do
begin
        Chart1.Axes.Bottom.Items.Add(Chart1[i].XValues[j],FloatToStr(Chart1[i].XValues[j]));
end;
Chart1.Axes.Bottom.LabelsAngle:=90;
end;
end;
Please, can you tell us if previous code solves your problem with labels?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Wed Sep 07, 2011 3:51 pm

Sorry, I know my code may be a little confusing unless viewed and understood in the full spectrum.

I do in fact, though, add a Label to every reading (or Point):

Code: Select all

sgSeriesGroup.Series[i3].AddXY(
   aReadingRecord[i2].dTestDate,
   aReadingRecord[i2].fReading,
   DateToStr(aReadingRecord[i2].dTestDate));
So every Point on the graph does have a Label associated with it.

I must add the XY values hence I'm using the AddXY code.
The graph is broken into series which belong to different Y axes that's why my code looks the way it does.

Also, there is no Add function that takes 2 arguments for Axes.Bottom.Items, it takes only one argument that's a double (for my version anyways).

I was trying to play around with some of your suggestions, but it's not working out.
I will keep trying, perhaps there is something else we can do?

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Wed Sep 07, 2011 7:08 pm

I went around a different route, however it still get a similar (and undesired) result.
But, at least this code should be easier to understand.
So omitting how I create the records, axes, groups, this I believe makes a little bit more sense as a "stand alone" code:

Code: Select all

      with fraPCTGraph.chtGraph do
      begin
         for i := 0 to SeriesGroups.Count - 1 do
         begin
            for i2 := 0 to SeriesGroups[i].Series.Count - 1 do
            begin
               for i3 := 0 to Length(aReadingRecord) - 1 do
               begin
                  if (aReadingRecord[i3].sProduct = SeriesGroups[i].Name) AND
                     (aReadingRecord[i3].sSeries+' ('+SeriesGroups[i].Name+')'
                        = SeriesGroups[i].Series[i2].Title)
                  then
                  begin
                     SeriesGroups[i].Series[i2].AddXY(aReadingRecord[i3].dTestDate,
                        aReadingRecord[i3].fReading,
                        DateToStr(aReadingRecord[i3].dTestDate));
                  end;
               end;//for i3 := 0 to Length(aReadingRecord) - 1 do
            end;//for i2 := 0 to SeriesGroups[i].Series.Count - 1 do
         end;//for i := 0 to SeriesGroups.Count - 1 do

         Draw;
         MarginUnits := muPixels;
         MarginLeft := CustomAxes[0].MaxLabelsWidth + CustomAxes[0].TickLength + 25;
         MarginRight := 35;

      end;//with fraPCTGraphByAnalysis.chtGraph do
It, just like the other way around, works just fine. Adds correct values to correct axes and series, just the labels are still missing from some values :(
Attachments
teechart_bad5.JPG
teechart_bad5.JPG (84.53 KiB) Viewed 10053 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart formats strange at runtime after dynamic code

Post by Sandra » Thu Sep 08, 2011 12:02 pm

Hello Metegrity Inc.

We have made a simple code to try to reproduce your problem here:

Code: Select all

Uses Series,Math, TeCanvas;

procedure TForm3.FormCreate(Sender: TObject);
var i,j:Integer;
    Green,Blue : TChartAxis;
    Series1, Series2, Series3: TLineSeries;
    tmp: TDateTime;
begin
  Series1:=Chart1.AddSeries(TLineSeries) as TLineSeries;
  Series2:=Chart1.AddSeries(TLineSeries) as TLineSeries;
  Series3:=Chart1.AddSeries(TLineSeries) as TLineSeries;

  tmp:=Date;

  Series1.XValues.DateTime:=True;
  Series1.AddXY(tmp+3,15,DateToStr(tmp+3));
  Series1.AddXY(tmp+7,20, DateToStr(tmp+7));

  Series2.XValues.DateTime:=True;
  Series2.AddXY(tmp+4,10,DateToStr(tmp+4));
  Series2.AddXY(tmp+15,25,DateToStr(tmp+15));
  Series2.AddXY(tmp+22,50,DateToStr(tmp+22));
  Series2.AddXY(tmp+12,30,DateToStr(tmp+12));

  Series3.XValues.DateTime:=True;
  Series3.AddXY(tmp+21,110,DateToStr(tmp+21));
  Series3.AddXY(tmp+23,30,DateToStr(tmp+23));
  Series3.AddXY(tmp+11,55,DateToStr(tmp+11));

  Series1.Pointer.Visible:=True;
  Series2.Pointer.Visible:=True;
  Series3.Pointer.Visible:=True;

  Chart1.View3D:=False;
  Chart1.Legend.Visible:=false;

  { change the Left axis properties }
  With Chart1.LeftAxis do
  begin
    Axis.Color:=Series1.Color;
    StartPosition:=0;
    EndPosition:=33;
  end;

  { create custom axes. This can be done at design-time
    with the chart editor. }
  Green:=TChartAxis.Create(Chart1.CustomAxes);
  With Green do
  begin
   Axis.Color:=Series2.Color;
   StartPosition:=33;
   EndPosition:=66;
  end;

  Blue:=TChartAxis.Create(Chart1.CustomAxes);
  With Blue do
  begin
   Axis.Color:=Series3.Color;
   StartPosition:=66;
   EndPosition:=100;
  end;

  { associate series }
  Series1.VertAxis:=aLeftAxis;
  Series2.CustomVertAxis:=Green;
  Series3.CustomVertAxis:=Blue;

  Chart1.Axes.Bottom.LabelsAngle:=90;

  { use custom labels }
  Chart1.Axes.Bottom.Items.Clear;
  for i := 0 to Chart1.SeriesCount- 1 do
  begin
    For  j:=0 To Chart1[i].Count-1 do
    begin
      Chart1.Axes.Bottom.Items.Add(Chart1[i].XValues[j], DateToStr(Chart1[i].XValues[j]));
    end;
  end;
end;
Testing previous code, in last version of TeeChartVCL(build 8.08.80307), we couldn’t reproduce your problem and we can see, there are three overloads of method Add with next headers:

Function TAxisItems.Add(const Value: Double):TAxisItem;
Function TAxisItems.Add(const Value: Double; const Text: String):TAxisItem;
Function TAxisItems.Add(const Value: Double; const Text:String; const Font:TTeeFont):TAxisItem;


So, I recommend you, update your version 8 of TeeChartVCL to last release, you can find in this link and check again if your problem persists. On the other hand, if you have any reason that you don't allow update your version, please let me know.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Thu Sep 08, 2011 2:16 pm

So what you're saying is that there are no overloads of that method in my version, is that correct?

We will for sure not upgrade before the release which is coming up at the end of the week (relatively speaking), but we may consider that for further version (just to avoid any issues with our graphs, we have quite a few in our software).

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart formats strange at runtime after dynamic code

Post by Sandra » Fri Sep 09, 2011 1:25 pm

Hello Metegrity Inc.
So what you're saying is that there are no overloads of that method in my version, is that correct?
So sorry, I think, I haven't explained well, I wanted tell, you have different overloads of add method, to add labels in the axis items. Is also true, that in last version 8 there are some modifications may be useful you to achieve as you want and improve performance of your application.

Thank you.
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metegrity Inc.
Newbie
Newbie
Posts: 10
Joined: Thu Aug 14, 2008 12:00 am
Contact:

Re: Chart formats strange at runtime after dynamic code

Post by Metegrity Inc. » Sat Sep 10, 2011 9:11 pm

AHA!

YES!

Sorry, for some reason I "wasn't seeing" the overloads, but they are in fact there.
Anyways your solution worked!

Thank you! That makes the graph pretty much bug free as far as I'm concerned right now :)

Post Reply