Page 1 of 1

Marks and Crosstab

Posted: Mon May 25, 2015 1:10 pm
by 9231501
I'm using a TDBChart with Crosstab datasource and Bar series. In the chart editor, I can set the marks as not visible and the chart is previewed correctly (without the marks). But in runtime, when the chart is draw, only the marks of the first series are hidden... all the marks of the other series are visible.

I tried to do this, but it didnt help:

Code: Select all

      myDataset.Open;
      myCrossTab.Refresh;
      with DBChart11 do
      begin
        for I := 0 to SeriesCount -1 do
          Series[i].Marks.Visible:=false;
      end;
Also, the horizontal (bottom) axis is set to DateTime and format MM/yyyy, but it is draw as a full date, without respecting the format.

Any help?

Carlos

Re: Marks and Crosstab

Posted: Mon May 25, 2015 7:37 pm
by 9231501
Well, I could solve the problem with the Marks... the problem is that that piece of code was inside a DisableControls/EnableControls session, and when EnableControls is called, for some reason, the chart make the series marks visible again.

Still could not solve the Axis format problem.

Re: Marks and Crosstab

Posted: Tue May 26, 2015 2:05 pm
by yeray
Hello,
WarmBooter wrote:Also, the horizontal (bottom) axis is set to DateTime and format MM/yyyy, but it is draw as a full date, without respecting the format.
WarmBooter wrote:Still could not solve the Axis format problem.
Maybe you've set labels on the series. Note that by default the bottom axis labels style is set to "Auto" and this show the series labels if they are populated.
If that's not the case we'll need to see how are you setting your chart, so I'd ask for a simple example project we can run as-is to reproduce the problem here.

Re: Marks and Crosstab

Posted: Tue May 26, 2015 4:19 pm
by 9231501
The Axis labels are set as Marks, since this was the only way I found to have the desired value printed. The problem is that it doesn't respect the datetime format mask that I had defined.

Re: Marks and Crosstab

Posted: Wed May 27, 2015 8:25 am
by yeray
Hello,

Then the problem will probably be in the formatting of the datetime when you are adding it to the values.
If you are using Add(value, label, color) to add your points to the series, check that "label" string you are entering has the correct string.

The Axis DateTimeFormat is only used when LabelStyle is set to talValue, talPointValue or talAuto (talAuto - without labels on the series).

Re: Marks and Crosstab

Posted: Wed May 27, 2015 11:43 am
by 9231501
Yeray wrote:Hello,
Then the problem will probably be in the formatting of the datetime when you are adding it to the values.
If you are using Add(value, label, color) to add your points to the series, check that "label" string you are entering has the correct string.
The source of the data is a query and the chart is configured as crosstab, so all points, etc. are being added automatically.
Yeray wrote: The Axis DateTimeFormat is only used when LabelStyle is set to talValue, talPointValue or talAuto (talAuto - without labels on the series).
Problem is that using Value, PointValue or Auto doesnt display the desired value... only setting as Marks did it (almost).

Image

Re: Marks and Crosstab

Posted: Wed May 27, 2015 1:18 pm
by yeray
Hello,

Check the values of the "REFERENTE" field at the "tqCancelamentos" dataset. This field probably contains strings formatted from a date as "dd/mm/yyyy".

Re: Marks and Crosstab

Posted: Wed May 27, 2015 1:36 pm
by 9231501
Yeray wrote:Hello,
Check the values of the "REFERENTE" field at the "tqCancelamentos" dataset. This field probably contains strings formatted from a date as "dd/mm/yyyy".
In the dataset, REFERENTE is a TDateField, so, not a string. Also, no displayformat assigned to it.

Carlos

Re: Marks and Crosstab

Posted: Wed May 27, 2015 4:14 pm
by yeray
Hi Carlos,

I see TDBCrossTabSource takes the label field set and formats it without considering the Axis DateTimeFormat:

Code: Select all

tmpLabel:=tmpLabelField.AsString;
I'm not sure if modifying this would be a good idea. Ie note that having "MM/yyyy" as DateTimeFormat you'd loose the day information and then you wouldn't be able to show the day in the marks or anywhere else.

At this moment, the best workaround I can think on would be using the Chart OnGetAxisLabel to convert the label to DateTime and then back to string using your axis DateTimeFormat. Ie:

Code: Select all

uses DateUtils;

procedure TForm1.DBChart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
var tmpDate: TDateTime;
begin
  if (Sender = DBChart1.Axes.Bottom) then
  begin
    tmpDate:=StrToDateTimeDef(LabelText, Today);
    LabelText:=FormatDateTime(DBChart1.Axes.Bottom.DateTimeFormat, tmpDate);
  end;
end;

Re: Marks and Crosstab

Posted: Wed May 27, 2015 5:42 pm
by 9231501
Yeray wrote: I'm not sure if modifying this would be a good idea. Ie note that having "MM/yyyy" as DateTimeFormat you'd loose the day information and then you wouldn't be able to show the day in the marks or anywhere else.
In my case, this would not be a problem, since the day is always 01. I use that field to represent the month+year that something refers to (day doesn't matter, so it is stored always as day 1).

Carlos

Re: Marks and Crosstab

Posted: Thu May 28, 2015 11:04 am
by yeray
Hi Carlos,

Another alternative would be triggering the series' OnAfterAdd event to modify the label of point that has been added. Ie using the "orders" table in the "TeeChart Pro Database" shipped with the installation:

Code: Select all

uses Series, DBTables, TeeDBCrossTab, TeeDBCrossTabEditor, DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var Series1: TBarSeries;
    Table1: TTable;
    DBCrossTabSource1: TDBCrossTabSource;
begin
  DBChart1.View3D:=false;
  DBChart1.Axes.Bottom.DateTimeFormat:='MM/yyyy';

  Table1:=TTable.Create(Self);
  with Table1 do
  begin
    DatabaseName:='TeeChart Pro Database';
    TableName:='orders';
    Filter:='EMPNO=4';
    Filtered:=True;
  end;

  DBCrossTabSource1:=TDBCrossTabSource.Create(Self);
  with DBCrossTabSource1 do
  begin
    DataSet:=Table1;
    GroupField:='EMPNO';
    LabelField:='SALEDATE';
    ValueField:='ITEMTOTAL';
  end;

  Series1:=DBChart1.AddSeries(TBarSeries) as TBarSeries;
  with Series1 do
  begin
    //OnAfterAdd:=SeriesAfterAdd;  // uncomment this to activate the workaround
    DataSource:=DBCrossTabSource1;
    XValues.DateTime:=True;
  end;

  DBCrossTabSource1.Series:=Series1;
  DBCrossTabSource1.Active:=true;
  Table1.Active:=true;
end;

procedure TForm1.SeriesAfterAdd(Sender:TChartSeries; ValueIndex:Integer);
var tmpDate: TDateTime;
begin
  tmpDate:=StrToDateTimeDef(Sender.Labels[ValueIndex], Today);
  Sender.Labels[ValueIndex]:=FormatDateTime(DBChart1.Axes.Bottom.DateTimeFormat, tmpDate);
end;