Jac*_*cob 4 c# winforms livecharts
我有一个在 winform 中使用实时图表的饼图,并且我尝试使用文档中的代码将工具提示更改为当前悬停:
pieChart1.DataTooltip.SelectionMode = LiveCharts.TooltipSelectionMode.OnlySender;
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误: 严重性代码 描述 项目文件行抑制状态
'UserControl' does not contain a definition for 'SelectionMode' and no accessible extension method 'SelectionMode' accepting a first argument of type 'UserControl' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
我不确定我错过了什么?下面的代码是我用来绘制饼图的代码。
Func<ChartPoint, string> labelPoint = chartPoint =>
string.Format("${0:n}", chartPoint.Y, chartPoint.Participation);
SeriesCollection series = new SeriesCollection();
//reads in a data table and creates a pie series for each data row
foreach (DataRow dr in dt.Rows)
{
PieSeries ps = new PieSeries
{
Title = dr["Name"].ToString(),
Values = new ChartValues<double> {
double.Parse(dr["Budget Amount"].ToString())},
DataLabels = true,
LabelPoint = labelPoint
};
series.Add(ps);
}
pieChart1.Series = series;
pieChart1.LegendLocation = LegendLocation.Bottom;
pieChart1.DataTooltip.SelectionMode = LiveCharts.TooltipSelectionMode.OnlySender;
Run Code Online (Sandbox Code Playgroud)
DataTooltip 可以是任何 WPF 用户控件。因此,要更改 SelectionMode,您需要将其转换为DefaultTooltip.
var tooltip = (LiveCharts.DefaultTooltip) pieChart1.DataTooltip
tooltip.SelectionMode = LiveCharts.TooltipSelectionMode.OnlySender
Run Code Online (Sandbox Code Playgroud)