Rav*_*tal 3 c# mschart winforms
我正在开发一个仪表板系统,我在 WinForms 中使用折线图。我需要在每一行上显示 tooptip。我试过这个
var series = new Series
{
Name = chartPoint.SetName,
Color = chartPoint.ChartColor,
ChartType = SeriesChartType.Line,
BorderDashStyle = chartPoint.ChartDashStyle,
BorderWidth = chartPoint.BorderWidth,
IsVisibleInLegend = !chartPoint.HideLegend,
ToolTip = "Hello World"
};
Run Code Online (Sandbox Code Playgroud)
但它对我不起作用
您有两个选项,要么使用KeywordsChart 控件接受。
myChart.Series[0].ToolTip = "Name #SERIESNAME : X - #VALX{F2} , Y - #VALY{F2}";
Run Code Online (Sandbox Code Playgroud)
在Chart控件中,aKeyword是一个字符序列,在运行时会替换为自动计算的值。有关图表控件接受的关键字的完整列表,请查找关键字参考
或
如果你想要更奇特的东西,你必须处理这个事件 GetToolTipText
this.myChart.GetToolTipText += new System.Windows.Forms.DataVisualization.Charting.Chart.ToolTipEventHandler(this.myChart_GetToolTipText);
Run Code Online (Sandbox Code Playgroud)
现在我不确定你想在工具提示上显示什么,但你可以相应地添加逻辑。假设您想显示DataPoints系列中的值
private void myChart_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
{
switch(e.HitTestResult.ChartElementType)
{
case ChartElementType.DataPoint:
e.Text = myChart.Series[0].Points[e.HitTestResult.PointIndex]).ToString()
+ /* something for which no keyword exists */;
break;
case ChartElementType.Axis:
// add logic here
case ....
.
.
default:
// do nothing
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8858 次 |
| 最近记录: |