TChart 系列值的鼠标悬停提示
我在 Delphi 7 中使用 TChart,我想显示一些条形图。 我使用以下代码从数据库查询中设置系列值:
chart1.FreeAllSeries;
chart1.SeriesList.Clear;
chart1.AddSeries(TBarSeries.Create(Self));
TBarSeries(chart1.Series[0]).BarStyle:=bsRectGradient;
with query1 do
begin
Close;
Execute;
while not EoF do
begin
chart1.Series[0].Add(FieldAsFloat('sum_actual_days'), FieldAsString('contract_no'));
Next;
end;
end;
每个条形(值)现在都在条形下方和条形上方的黄色矩形中显示标签。
我不想重复标签值两次,而是从查询中获得了一些附加信息,我希望将其显示在栏上方而不是标签上(或者最好作为鼠标悬停提示)。 这可以用 TChart 完成吗? 如何... ?
I am using a TChart in Delphi 7, and I want to display some bar charts. I am using the following code to set up the series values from a database query:
chart1.FreeAllSeries;
chart1.SeriesList.Clear;
chart1.AddSeries(TBarSeries.Create(Self));
TBarSeries(chart1.Series[0]).BarStyle:=bsRectGradient;
with query1 do
begin
Close;
Execute;
while not EoF do
begin
chart1.Series[0].Add(FieldAsFloat('sum_actual_days'), FieldAsString('contract_no'));
Next;
end;
end;
Each bar (value) is now showing the label both below the bar, and in a yellow rectangle above the bar.
Instead of repeating the label value twice, I have some additional information from the query that I would like to show above the bar instead of the label (or, preferably, as a mouseover hint). Can this be done with the TChart? And how... ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可以通过使用 TChart 图表的 OnMouseMove 事件来完成。 类似这样的事情应该可以帮助您开始:
当然,用于填充图表的查询必须仍然打开,此代码才能工作。
This can be done with a TChart by using the chart's OnMouseMove event. Something like this should get you started:
Of course, the query that you used to populate the chart must still be open for this code to work.
“标记提示”工具提供了一个事件来提供自定义文本(OnGetText 事件):
The "Mark Tips" tool provides an event to supply custom text (OnGetText event):
有“标记提示”工具,可让您在移动到栏上时显示提示。 但我不确定您是否可以修改提示以显示自定义数据而不是预定义的样式。
There is the "Mark Tips" tool that allows you to show a hint when you move over a bar. But I'm not sure if you can modify the tip to show custom data instead of the predifined styles.
您可以将面板放入图表中,并将其用作提示。 使用 NearestPoint 工具效果非常好。
首先将NearestPoint工具添加到图表中(双击图表,选择工具/添加)。
然后将面板添加到图表(图表组件中)并根据您的需要设置样式。
然后使用OnMouseMove事件:
如果你愿意,你可以禁用NearestPoint工具,但我们需要它来轻松找到对应的点。
You can put a Panel into the Chart, and use it as a hint. With the NearestPoint tool it works very well.
First add the NearestPoint tool to the chart (Double click on the chart, select Tools / Add).
Then add a Panel to the Chart (into the Chart component) and style it according to your needs.
Then use the OnMouseMove event:
If you want, you can disable the NearestPoint tool, but we need it to easily find the corresponding point.