我是一名新手,并且正在使用StringGrid和GanttChart进行C ++ VCL项目。我想做的是,一旦在StringGrid中输入了新数据,就会自动“更新”甘特栏。

我首先要做的是使用以下命令创建带有条形图的图表:

TGanttSeries *Series1;
 int i = 0;

Series1 = new TGanttSeries(this);
Series1->AddGantt(StrToDate(StringGridEd1->Cells[4][1]),StrToDate(StringGridEd1->Cells[5][1]), i,"Task"+IntToStr(i));
Series1->ParentChart = Chart1;


这非常适合创建图表,但是如何更新甘特图的柱形图日期,以便柱形图自动调整大小?例如,如果用户输入1天,则甘特图条仅显示1天,而当用户输入5天时,甘特图条会自动将其自身从1天调整为5天。

有什么功能或属性可以帮我吗?

最佳答案

我刚刚在Steema Software官方论坛(here)上答复了您。
我在这里复制答案:

如果我理解正确,则可以在StringGrid1SetEditText事件中更新您的系列StartValues / EndValues。即:

TGanttSeries *Series1;

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  StringGrid1->ColCount = 6;
  StringGrid1->RowCount = 2;
  StringGrid1->Cells[4][1] = "01/01/2016";
  StringGrid1->Cells[5][1] = "02/01/2016";
  StringGrid1->Options << goEditing;

  int i = 0;

  Series1 = new TGanttSeries(this);
  Series1->AddGantt(StrToDate(StringGrid1->Cells[4][1]),StrToDate(StringGrid1->Cells[5][1]), i,"Task"+IntToStr(i));
  Series1->ParentChart = Chart1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int ACol, int ARow,
          const UnicodeString Value)
{
  TDateTime tmp;

  if ((ACol==4) || (ACol==5)) {
    if (TryStrToDate(StringGrid1->Cells[ACol][ARow], tmp)) {
      if (ACol==4) {
        Series1->StartValues->Value[ARow-1] = tmp;
        Series1->StartValues->Modified = true;
      }
      else {
        Series1->EndValues->Value[ARow-1] = tmp;
        Series1->EndValues->Modified = true;
      }
    }
  }
}

09-04 18:49