How to customize MarksTip text of Teechart in C# when mouse moving?
如何在C# TeeChart控件当中,自定义鼠标移动时MarksTip显示的内容?例如显示所有系列的值?
1. 添加TeeChart控件,并添加3个系列。
2. 在Teechart中,属性,Tools,add, Mark Tips
3. 在窗体中, 找到Teechart控件,添加事件MouseMove:
private int MarksSeriesIndex = -1;
private Steema.TeeChart.TChart MarksTipChart = null;
private void tChart_MouseMove(object sender, MouseEventArgs e)
{
MarksTipChart = (Steema.TeeChart.TChart)sender;
for (int i = 0; i < MarksTipChart.Series.Count; i++)
{
MarksSeriesIndex = MarksTipChart[i].Clicked(e.X, e.Y);
if (MarksSeriesIndex != -1) return;
}
MarksSeriesIndex = -1;
}
4 在窗体中,找到MarksTip1,在事件(Event)当中,找到GetText事件,双击,写代码:
private void marksTip_GetText(Steema.TeeChart.Tools.MarksTip sender, Steema.TeeChart.Tools.MarksTipGetTextEventArgs e)
{
if (MarksSeriesIndex > -1)
{
e.Text = "时间: " + MarksTipChart[0].XValues.AsDateTime(MarksSeriesIndex);
for (int i = 0; i< MarksTipChart.Series.Count; i++)
{
e.Text += "\r\n" + MarksTipChart[i].Title + ": " + MarksTipChart[i].YValues[MarksSeriesIndex].ToString();
}
}
}
上面的代码,可以适用于多个Teechart控件!
也可以添加一个cursorTool,在cursorTool的Change事件当中,给MarksSeriesIndex赋值:
private void cursorTool1_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
{
MarksSeriesIndex = e.ValueIndex;
}
这样就不需要MouseMove当中获取ValueIndex了。