Duplicate Values in X axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
McMClark
Newbie
Newbie
Posts: 50
Joined: Thu Apr 15, 2004 4:00 am

Duplicate Values in X axis

Post by McMClark » Sat Nov 04, 2006 7:15 pm

I am using a DBChart to show integer values on the y axis and a month and year string on the x axis. I am displaying a line graph. Each line represents a company. I build each company's results a line at a time (see code below). The problem is that some of the months and years are being duplicated on the x axis and the lines are not in sync visually. Such that October 2006 appears twice for the companies that have data for October. Can you help? Is my mehodology of building the data in the chart correct?

The code is below:

Companys_Query2.Close;
Companys_Query2.SQL.Clear;
Companys_Query2.Sql.Add('Select Distinct Company, CompanyID from Companys');
Companys_Query2.ActiveRuntime := True;

DBChart1.RemoveAllSeries;
DBChart1.LeftAxis.Automatic := True;
if blRestrictPoints then
begin
DBChart1.MaxPointsPerPage := intMaxPointsPerPage;
end
else
begin
DBChart1.MaxPointsPerPage := 0;
end;

DBChart1.Legend.Title.Font.Name := 'Times New Roman';
DBChart1.Legend.Title.Font.Size := 8;
DBChart1.LeftAxis.LabelsFont.Name := 'Times New Roman';
DBChart1.LeftAxis.LabelsFont.Size := 8;
DBChart1.BottomAxis.LabelsFont.Name := 'Times New Roman';
DBChart1.BottomAxis.LabelsFont.Size := 8;

for intList := 1 to Companys_Query2.RecordCount do
begin
strCompany := Companys_Query2.FieldByName('Company').asString;
intCompanyID := Companys_Query2.FieldByName('CompanyID').asInteger;
TempResults_Query1 := TnxQuery.Create(self);
TempResults_Query1.Database := frmSearch.Extractor_Database1;
TempResults_Query1.SQL.Add('SELECT Case _month ');
TempResults_Query1.SQL.Add('when 1 then ' + '''January ''');
TempResults_Query1.SQL.Add('when 2 then ' + '''February ''');
TempResults_Query1.SQL.Add('when 3 then ' + '''March ''');
TempResults_Query1.SQL.Add('when 4 then ' + '''April ''');
TempResults_Query1.SQL.Add('when 5 then ' + '''May ''');
TempResults_Query1.SQL.Add('when 6 then ' + '''June ''');
TempResults_Query1.SQL.Add('when 7 then ' + '''July ''');
TempResults_Query1.SQL.Add('when 8 then ' + '''August ''');
TempResults_Query1.SQL.Add('when 9 then ' + '''September ''');
TempResults_Query1.SQL.Add('when 10 then ' + '''October ''');
TempResults_Query1.SQL.Add('when 11 then ' + '''November ''');
TempResults_Query1.SQL.Add('when 12 then ' + '''December ''');
TempResults_Query1.SQL.Add('end || Cast(_year as char(4)) as period, sum(entityhits) as total ');
TempResults_Query1.SQL.Add('from ');
TempResults_Query1.SQL.Add('(select extract(year from publicationdate) _year, ');
TempResults_Query1.SQL.Add('extract(month from publicationdate) _month, entityhits from ' + strExtractTableName + ' as B, PublisherCredibility as C ' );
TempResults_Query1.SQL.Add(' where B.PublisherID=C.PublisherID and B.ElementID =:intElementID and C.PublisherCredibility>=:dbPublisherCredibilityThreshold ');
TempResults_Query1.SQL.Add(' and B.CountryID=:CountryID ');
TempResults_Query1.SQL.Add(' order by _year, _month) t group by _year, _month;');
TempResults_Query1.ParamByName('intCompanyID').AsInteger := intCompanyID;
TempResults_Query1.ParamByName('CountryID').AsInteger := CountryID;
TempResults_Query1.ParamByName('dbPublisherCredibilityThreshold').AsFloat := dbPublisherCredibilityThreshold;
if TempResults_Query1.Prepared = False then
begin
TempResults_Query1.Prepare;
end;
TempResults_Query1.ActiveRuntime := True;

if TempResults_Query1.RecordCount > 0 then
begin
if TempResults_Query1.RecordCount = 1 then
begin
intList2 := intList2 + 1;
tmplineSeries := TLineSeries.Create(Self);
DBChart1.AddSeries(tmpLineSeries);
DBChart1.Legend.Visible := True;
DBChart1.Legend.CheckBoxes := True;

if blRestrictPoints then
begin
DBChart1.MaxPointsPerPage := intMaxPointsPerPage;
end
else
begin
DBChart1.MaxPointsPerPage := 0;
end;
With tmpLineSeries do
Begin
DataSource:= TempResults_Query1;
YValues.ValueSource := 'Total';
XLabelsSource := 'Period';

//XValues.DateTime := True;
Title := strElement;

case intList2 of
1 :Begin
tmpLineSeries.Color := $00408080;
end;
2 :Begin
tmpLineSeries.Color := $00A4C7A3;
end;
3 :Begin
tmpLineSeries.Color := $00804000;
end;
4 :Begin
tmpLineSeries.Color := $004080FF;
end;
5 :Begin
tmpLineSeries.Color := $00400080;
end;
6 :Begin
tmpLineSeries.Color := $00C08080;
end;
7 :Begin
tmpLineSeries.Color := $00B3FFFF;
end;
8 :Begin
tmpLineSeries.Color := clAqua;
end;
9 :Begin
tmpLineSeries.Color := $00FF8000;
end;
10:Begin
tmpLineSeries.Color := $00A4C7A3;
end;
end;

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Nov 06, 2006 2:36 pm

Hi McMClark,

It is difficult to guess what's happening without being able to reproduce the problem here. I imagine your problem can be solved setting the bottom axis scaling and format correctly. You'll find more information about that in Tutorial 4 - Axis Control. Tutorials can be found at TeeChart's program group.
Best Regards,
Narcís Calvet / 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

McMClark
Newbie
Newbie
Posts: 50
Joined: Thu Apr 15, 2004 4:00 am

Post by McMClark » Mon Nov 06, 2006 7:49 pm

I have some more information. Some companies have more months of data than others. For instances, Company A may have 20 months and Company B may have 35. What I see happenning is that the lines are not in sync with the x axis. The only line that is in sync is the line with the most months. For instances, the last data I have for Company A and Company B is for October 2006. But with both lines showing on the DBChart, Company A's October data is lining up with June 2006 and ends at that label while Company B data continues for 4 more points.

Secondly, I do not have the tutorials on my system. Is there any way to download them?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Nov 07, 2006 9:56 am

Hi McMClark,

Aren't you populating all series following the same scale? I mean, if you have less values for one series but you set its X values then all series should scale accordingly.

Regarding the tutorials, you need to install TeeChart using the binary installer specific for each IDE, you can find them at the client area. If you are a source code customer we recommend you install the binary installer and then the source code installer.
Best Regards,
Narcís Calvet / 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

Post Reply