【问题标题】:TChart size of bar-series changes条形系列变化的 TChart 大小
【发布时间】:2019-08-22 06:58:44
【问题描述】:

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

饼图最多可包含 7 个饼图(用户请求)。如果有超过 7 个值(我没有使用 OtherPie 功能),则会创建一个“其他”饼图,当您单击该“其他”饼图时,条形图将变为可见。该条形系列的值被添加到饼图的图例中。工作正常。

现在我选择 period october,单击 other-pie,条形图变为可见。我选择下一个周期,单击其他饼图,条形图再次变为可见。但是然后我回到上一时期,单击其他饼图,条形图变得可见,但要小得多!太小 ! 再次选择下一个perioda,bar-chart很好,返回,bar-chart很小。

请看问题的屏幕录像: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;

【问题讨论】:

    标签: delphi vcl teechart


    【解决方案1】:

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

    AChart.LeftAxis.Maximum := ABarSeries.MaxYValue;
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 2018-03-09
      相关资源
      最近更新 更多