Setting LabelFrequency of a chart

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
DrTob
Posts: 20
Joined: Tue Jul 19, 2011 2:31 pm

Setting LabelFrequency of a chart

Post by DrTob »

I create a new Chart on a sheet with

Code: Select all

 sheet.Charts.Add(sheet.Index);
everything works well. But if I have many values excel only prints every second (or less) label.

If tried to set the label frequency with:

Code: Select all

chart.PlotArea.SerieAxis.CatSerAxisScaling.LabelsFrequency := 1;
but this results in an Error "Property has no data", because the record of "CatSerAxisScaling" is nil.

how can I set the labelfrequency and orientation of the chart?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Setting LabelFrequency of a chart

Post by larsa »

Hello

Sorry, I have no idea how to do this. To find out how, create an excel file with the settings you want and check what values excel sets.
Lars Arvidsson, Axolot Data
DrTob
Posts: 20
Joined: Tue Jul 19, 2011 2:31 pm

Re: Setting LabelFrequency of a chart

Post by DrTob »

Hello,

i've figured out, that the right setting is

Sheet.PlotArea.CategoryAxis.CatSerAxisScaling.LabelsFrequency

however I'm not able to set this Value in a new created file.
If I open a created file in EXCEL (2013), the "best fitting" value is selected. If I save the File (without any changes!) and Reset LabelsFrequency to 1, the setting is used.

Sample:

Code: Select all

procedure CreateSample;
var
    xls: TXLSReadWriteII4;
    I: Integer;
    chart : TDrwChart;
begin
    xls := TXLSReadWriteII4.Create(nil);
    try
        xls.FileName := 'test.xls';
        xls.Sheets.Add().Name := 'data';
        for I := 0 to 99 do begin
            xls.sheet[1].AsString[0,I] := 'Value' + IntToStr(I);
            xls.Sheet[1].AsInteger[1,I] := Random(100);
        end;
        xls.sheet[0].Charts.Clear;
        chart := xls.sheet[0].Charts.Add(0);
        chart.Row1 := 6;
        chart.Row2 := 30;
        chart.Col1 := 0;
        chart.Col2 := 12;
        chart.series.Items[0].Values := '''data''!B1:B100';
        chart.PlotArea.ValueAxis.ValueAxisScaling.MinValue := 0;
        chart.PlotArea.ValueAxis.ValueAxisScaling.MaxValue := 100;
        chart.PlotArea.ValueAxis.ValueAxisScaling.MajorInc := 10;
        chart.series.Items[0].Category := '''data''!A1:A100';
        chart.PlotArea.ValueAxis.Tick.MajorTick := ttOutside;
        chart.PlotArea.ValueAxis.Tick.MinorTick := ttInvisible;
        chart.PlotArea.HasLegend := false;
        chart.PlotArea.CategoryAxis.CatSerAxisScaling.LabelsFrequency := 1;
        xls.Write;
    finally
        xls.Free;
    end;
end;
When I open the created XLS in EXCEL, only every fourth label is shown. After saving it (without any changes) and read it again, chart.PlotArea.CategoryAxis.CatSerAxisScaling.LabelsFrequency is 4. Resetting it to 1 has the desired effect, EXCEL now shows all Lables.

Why is the initial setting ignored?
Post Reply