酒吧系列的TChart尺寸变化

时间:2019-08-22 06:58:44

标签: delphi vcl teechart

我有几个时期(几个月)的数据。选择时段时,将显示几个饼图。用户可以在该表格上单击以选择下一个或上一个期间,然后重新绘制反映该期间数据的图表。到目前为止一切顺利。

PieCharts最多可包含7个饼(用户请求)。如果有七个以上的值(我未使用OtherPie功能),则会创建一个“其他”饼,并且当您单击该“其他”饼时,将显示一个条形图。该Bar系列的值将添加到饼图的图例中。效果很好。

现在,我选择10月的周期,单击其他饼图,条形图变为可见。我选择下一个时段,单击其他饼图,然后再次显示条形图。但是,然后我回到上一个时期,单击其他饼图,条形图变得可见,但是要小得多!太小 ! 再次选择下一个周期,条形图就很好,返回,条形图就很小。

请查看该问题的屏幕录像:TChart Issue.wmv

对我来说,奇怪的是,我第一次显示10月的条形图,一切都很好,但是第二次以这种小格式显示。在我看来,已经发生了财产变更或其他事情。但这可能是错误的思维方向...

我查看了数据,尝试了几个属性,目前正在尝试缩放选项。我还向Steema寻求帮助,但到目前为止没有结果。

procedure FillChart(AChart: TChart; AOverviewItemList: TOverviewItemList; APieSeries: TPieSeries; ABarSeries: TBarSeries);
  var
    i:                  integer;
    vOVitem:            TOverviewItem;
    LValue:             double;
    LOtherValue:        double;
    LUseOtherPieIdx:    integer;
    LLabel:             string;
    t:                  integer;
  begin
    LSortedGraphItems.Clear;

    { because my users don't want to use the standard functionality of the     }
    { 'other'-slices, I first add the items to a stringlist, sort that list    }
    { so I can then use the first 6 values for the pie, and if there are more  }
    { values I create an 'other'-pie myself and put the values in a bar-series }

    { here the stringlist will be filled }
    for vOVItem in AOverviewItemList do
    begin
      LValue := vOVItem.Details[0].Periods[APeriod].Total;
      LLabel := vOVItem.ResultItem.Description;
      if abs(LValue) > 0 then
      begin
        LSortedGraphItems.Add(Format('%10.5f=%s',[LValue, LLabel]));
      end;
    end;

    { determine when to use values for otherpie, There should never be }
    { more than 7 pies in the pie-chart. }
    LUseOtherPieIdx := max(0, LSortedGraphItems.Count - 7);

    LSortedGraphItems.Sort;

    { always start clean }
    LOtherValue := 0;
    ABarSeries.Clear;

    { add values to either the pie- or the bar-series }
    for i := 0 to LSortedGraphItems.Count-1 do
    begin
      lValue  := StrToFloatDef(LSortedGraphItems.Names[i], 0);
      LLabel  := LSortedGraphItems.ValueFromIndex[i];

      if LValue < 0 then
      begin
        LValue := abs(LValue);
        LLabel := '-'+LLabel;
      end;

      if (LUseOtherPieIdx > 0) and (i <= LUseOtherPieIdx) then
      begin
        LOtherValue := LOtherValue + LValue;

        ABarSeries.Add(LValue, LLabel);
      end else
      begin
        APieSeries.Add(LValue, LLabel);
        APieSeries.Tag := 0;
      end;
    end;

    { add a 'other'-pie if necessary }
    if (LOtherValue > 0)then
    begin
      APieSeries.Add(LOtherValue, Translate('Other'));
      APieSeries.Tag := 1;
    end;
  end;

1 个答案:

答案 0 :(得分:0)

我的一位同事提出了以下解决方案。添加BarSeries的值后,添加

AChart.LeftAxis.Maximum := ABarSeries.MaxYValue;

一种解释是,LeftAxis的属性第一次很好,但是被11月的值覆盖。回到10月份,将LeftAxis属性设置为适合11月的值,这会使october栏看起来太小。