我正在使用带有 TChart Standard 4.04 的 Borland C++Builder 2006,但我遇到了问题。我有一个 TChart,当计算用户点击它的位置时,它无法进行此计算,似乎没有办法避免这个问题。其实我的感觉是,没有人点击图表,事件是自己内部抛出的。
附上你可以找到错误的详细信息,我想知道究竟在做什么,以尽量避免错误。我已经尝试避免将系列与图表断开连接的问题(更新系列内容时,ParentChart 属性为 NULL),但它仍然会发生。
此外,您还可以在同一张附图中找到有问题的图表(标记为红色)。下面,稍微解释一下该图表的情况。它包含3个系列:
1 TPoint系列:
该系列只有一个点,与下一个 TPointSeries 中选定的点在同一位置。
它显示更大的选定点,顶部图表(不会产生任何问题)显示选定项目的详细信息。
1 TPointSeries
- 该系列代表了演变,并且对于对患者进行的每项研究都有一个要点。
1 TLine系列
该系列代表了演变,并且对于对患者进行的每项研究都有一个要点。
最后,它加入了上一个系列的所有点。
在这里,是图像
我已经能够用下一个简单的单元重新创建问题。它包含一个显示 2 或 3 个点的图表。为了在 2 和 3 点之间进行更改,您可以使用按钮,或单击系列中的任何点。每次必须更新该图表时,所有系列都将被清空,并再次填充所需的数据。在这种状态下,如果您使用按钮或单击系列点,它不会失败。
但是,表单也有一个复选框,简单地说,在更新图表后增加了 1 秒的等待时间。在这种情况下,当图表中有 3 个点并且您单击任意点更改为 2 个点时,图表会更新并停止 1 秒。在这一秒之后,错误出现了。
这里,文件.h的代码:
//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <vector.h>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
//---------------------------------------------------------------------------
struct TItemInChart {
int IdMeasurement;
int Group;
TDateTime DateTime;
};
class TForm1 : public TForm
{
__published: // IDE-managed Components
TChart *Chart;
TLineSeries *Series_BgLine;
TPointSeries *Series_Points;
TPointSeries *Series_SelectedPoint;
TButton *Button2p;
TButton *Button3p;
TCheckBox *cbSleepAfterUpdate;
void __fastcall Button2pClick(TObject *Sender);
void __fastcall ChartClickSeries(TCustomChart *Sender,
TChartSeries *Series, int ValueIndex, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall FormShow(TObject *Sender);
private: // User declarations
vector<TItemInChart*> vSetOf2Items;
vector<TItemInChart*> vSetOf3Items;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
这里,文件.cpp的代码:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <Math.hpp>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//Set of 2 elements
TItemInChart *tf = new TItemInChart();
tf->IdMeasurement = 21;
tf->DateTime = Now();
tf->Group = 1;
vSetOf2Items.push_back(tf);
tf = new TItemInChart();
tf->IdMeasurement = 2;
tf->DateTime = Now() + 1;
tf->Group = 2;
vSetOf2Items.push_back(tf);
//Set of 3 elements
tf = new TItemInChart();
tf->IdMeasurement = 31;
tf->DateTime = Now();
tf->Group = 1;
vSetOf3Items.push_back(tf);
tf = new TItemInChart();
tf->IdMeasurement = 32;
tf->DateTime = Now() + 1;
tf->Group = 2;
vSetOf3Items.push_back(tf);
tf = new TItemInChart();
tf->IdMeasurement = 33;
tf->DateTime = Now() + 2;
tf->Group = 3;
vSetOf3Items.push_back(tf);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2pClick(TObject *Sender)
{
//Disconecting the series and the chart
Series_BgLine->ParentChart = NULL;
Series_Points->ParentChart = NULL;
Series_SelectedPoint->ParentChart = NULL;
//Deleting alle xisnting data
Series_Points->Clear();
Series_SelectedPoint->Clear();
Series_BgLine->Clear();
//Deciding which data I'm goping to load
vector<TItemInChart*> vSetOfItems;
if (Sender == Button2p) {
vSetOfItems = vSetOf2Items;
}
else{
vSetOfItems = vSetOf3Items;
}
//Loading the data.
TItemInChart *iic;
for (int i = 0; i < vSetOfItems.size(); i++){
iic = vSetOfItems[i];
//Adding to series
Series_Points->AddXY(i+1, iic->Group, "", clRed);
Series_BgLine->AddXY(i+1, iic->Group, "", clWhite);
if ( (iic->IdMeasurement == 21) || (iic->IdMeasurement == 33) ) {
//Adding to selected point serie.
Series_SelectedPoint->Clear();
Series_SelectedPoint->AddXY(i + 1, iic->Group, "", clRed);
}
}
//Conencting again the series with the chart
Series_BgLine->ParentChart = Chart;
Series_Points->ParentChart = Chart;
Series_SelectedPoint->ParentChart = Chart;
//Waiting only if user wants
if (cbSleepAfterUpdate->Checked) {
Sleep(1000);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartClickSeries(TCustomChart *Sender,
TChartSeries *Series, int ValueIndex, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
//When clicking on any serie point, we change from 2 to 3 points, and vice-versa.
if (Series_BgLine->Count() <= 2) {
Button2pClick(Button3p);
}
else{
Button2pClick(Button2p);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
//When starting, we fill the chart with 3 points
Button2pClick(Button3p);
}
//---------------------------------------------------------------------------
这里,文件.dfm的代码:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 328
ClientWidth = 556
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object Chart: TChart
Left = -11
Top = 0
Width = 565
Height = 292
AllowPanning = pmHorizontal
AllowZoom = False
BackWall.Brush.Color = clWhite
BackWall.Color = 7436151
BackWall.Pen.Color = clGray
BottomWall.Color = 7436151
Foot.AdjustFrame = False
Foot.Visible = False
MarginBottom = 3
MarginLeft = 10
MarginTop = 3
Title.AdjustFrame = False
Title.Color = 7436151
Title.Font.Charset = DEFAULT_CHARSET
Title.Font.Color = clWhite
Title.Font.Height = -11
Title.Font.Name = 'Arial'
Title.Font.Style = []
Title.Text.Strings = (
'HISTORY')
OnClickSeries = ChartClickSeries
BackColor = 7436151
BottomAxis.Automatic = False
BottomAxis.AutomaticMaximum = False
BottomAxis.AutomaticMinimum = False
BottomAxis.Axis.Color = clGray
BottomAxis.Axis.Width = 1
BottomAxis.AxisValuesFormat = '0'
BottomAxis.ExactDateTime = False
BottomAxis.Increment = 1.000000000000000000
BottomAxis.LabelsAngle = 90
BottomAxis.LabelsFont.Charset = ANSI_CHARSET
BottomAxis.LabelsFont.Color = clWhite
BottomAxis.LabelsFont.Height = -11
BottomAxis.LabelsFont.Name = 'Arial'
BottomAxis.LabelsFont.Style = []
BottomAxis.LabelsMultiLine = True
BottomAxis.LabelsSeparation = 1
BottomAxis.LabelsSize = 66
BottomAxis.LabelStyle = talValue
BottomAxis.Maximum = 7.000000000000000000
BottomAxis.Minimum = 1.000000000000000000
BottomAxis.MinorTickCount = 0
BottomAxis.MinorTickLength = 0
BottomAxis.StartPosition = 5.000000000000000000
BottomAxis.EndPosition = 95.000000000000000000
Frame.Color = clGray
LeftAxis.Automatic = False
LeftAxis.AutomaticMaximum = False
LeftAxis.AutomaticMinimum = False
LeftAxis.Axis.Color = clGray
LeftAxis.Axis.Width = 1
LeftAxis.ExactDateTime = False
LeftAxis.Increment = 1.000000000000000000
LeftAxis.LabelsFont.Charset = DEFAULT_CHARSET
LeftAxis.LabelsFont.Color = clWhite
LeftAxis.LabelsFont.Height = -11
LeftAxis.LabelsFont.Name = 'Arial'
LeftAxis.LabelsFont.Style = []
LeftAxis.LabelsMultiLine = True
LeftAxis.Maximum = 5.000000000000000000
LeftAxis.MinorTickCount = 0
LeftAxis.MinorTickLength = 0
LeftAxis.StartPosition = 10.000000000000000000
LeftAxis.EndPosition = 90.000000000000000000
LeftAxis.RoundFirstLabel = False
Legend.Visible = False
MaxPointsPerPage = 8
ScaleLastPage = False
View3D = False
View3DWalls = False
BevelOuter = bvNone
Color = 7436151
TabOrder = 0
object Series_BgLine: TLineSeries
Marks.ArrowLength = 8
Marks.Visible = False
SeriesColor = clWhite
Title = 'Series_BgLine'
Pointer.InflateMargins = True
Pointer.Style = psRectangle
Pointer.Visible = False
XValues.DateTime = False
XValues.Name = 'X'
XValues.Multiplier = 1.000000000000000000
XValues.Order = loAscending
YValues.DateTime = False
YValues.Name = 'Y'
YValues.Multiplier = 1.000000000000000000
YValues.Order = loNone
end
object Series_Points: TPointSeries
Cursor = crHandPoint
Marks.ArrowLength = 0
Marks.Visible = False
SeriesColor = 4227327
Title = 'Series_Points'
Pointer.HorizSize = 7
Pointer.InflateMargins = True
Pointer.Pen.Color = clRed
Pointer.Pen.Visible = False
Pointer.Style = psCircle
Pointer.VertSize = 7
Pointer.Visible = True
XValues.DateTime = False
XValues.Name = 'X'
XValues.Multiplier = 1.000000000000000000
XValues.Order = loAscending
YValues.DateTime = False
YValues.Name = 'Y'
YValues.Multiplier = 1.000000000000000000
YValues.Order = loNone
end
object Series_SelectedPoint: TPointSeries
Marks.ArrowLength = 0
Marks.Visible = False
SeriesColor = clMaroon
Title = 'Series_SelectedPoint'
Pointer.HorizSize = 11
Pointer.InflateMargins = True
Pointer.Pen.Color = clRed
Pointer.Pen.Visible = False
Pointer.Style = psCircle
Pointer.VertSize = 11
Pointer.Visible = True
XValues.DateTime = False
XValues.Name = 'X'
XValues.Multiplier = 1.000000000000000000
XValues.Order = loAscending
YValues.DateTime = False
YValues.Name = 'Y'
YValues.Multiplier = 1.000000000000000000
YValues.Order = loNone
end
end
object Button2p: TButton
Left = 24
Top = 298
Width = 99
Height = 25
Caption = 'Button 2 points'
TabOrder = 1
OnClick = Button2pClick
end
object Button3p: TButton
Left = 129
Top = 297
Width = 105
Height = 25
Caption = 'Button 3 Points'
TabOrder = 2
OnClick = Button2pClick
end
object cbSleepAfterUpdate: TCheckBox
Left = 416
Top = 304
Width = 121
Height = 17
Caption = 'Sleep after the update'
TabOrder = 3
end
end