【C1】【FlexChart】ToolTip引起空指针异常
本帖最后由 dddsssssqq 于 2022-6-6 09:51 编辑异常频率挺高的。看不出来怎么回事:'(
我看你已经设置了FlexChart.ToolTip,把Visibility设置一下就行
<c1:FlexChart.ToolTip>
<ToolTipVisibility="Collapsed" />
</c1:FlexChart.ToolTip> 本帖最后由 dddsssssqq 于 2022-5-11 10:05 编辑
<Window
Height="450"
Title="MainWindow"
Width="800"
mc:Ignorable="d"
x:Class="FlexChartDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<ScrollViewer.Resources>
<c1:ChartStyle
FontWeight="Bold"
LinePattern="Dash"
Stroke="Black"
StrokeThickness="0.2"
x:Key="ChartStyle" />
<Style TargetType="c1:FlexChart">
<Setter Property="ToolTipService.InitialShowDelay" Value="1000" />
</Style>
</ScrollViewer.Resources>
<c1:FlexChart
BindingX="Time"
ChartType="Column"
Width="640"
x:Name="flexChart">
<c1:FlexChart.DataLabel>
<c1:DataLabel Content="{}{y}%" Position="Top" />
</c1:FlexChart.DataLabel>
<c1:Series Binding="PDF" Tooltip="{}{y}%" />
<c1:Series
Binding="CDf"
ChartType="LineSymbols"
SymbolMarker="Dot"
SymbolSize="5" />
<c1:FlexChart.ToolTip>
<ToolTip Content="123" IsEnabled="True" />
</c1:FlexChart.ToolTip>
<c1:FlexChart.AxisY>
<c1:Axis
AxisLine="False"
MajorGrid="True"
MajorGridStyle="{StaticResource ChartStyle}"
MajorUnit="5"
Max="100"
Min="0"
Position="Left"
StaggeredLines="0" />
</c1:FlexChart.AxisY>
</c1:FlexChart>
</ScrollViewer>
</Grid>
</Window> 本帖最后由 dddsssssqq 于 2022-5-11 10:51 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using C1.WPF.Chart;
namespace FlexChartDemo;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private readonly List<int> _data = new();
private readonly List<SolidColorBrush> brushs = new() {
new SolidColorBrush(Colors.Red),
new SolidColorBrush(Colors.OrangeRed),
new SolidColorBrush(Colors.Orange),
new SolidColorBrush(Colors.Yellow),
new SolidColorBrush(Colors.YellowGreen),
new SolidColorBrush(Colors.GreenYellow)
};
private readonly int npts = 12;
private readonly Random rnd = new();
private List<DataItem> _data1;
private Series paretoLine;
public MainWindow() {
InitializeComponent();
for (var i = 0; i < 12; i++) {
_data.Add(rnd.Next(20, 100));
}
flexChart.ItemsSource = Data1;
flexChart.Series[0].SymbolRendering += Flexchart_SymbolRendering;
flexChart.Series[1].SymbolRendering += Flexchart_SymbolRendering;
}
public List<DataItem> Data1 {
get {
if (_data1 == null) {
var sum = _data.Sum() * 1.0;
var count = 0;
_data1 = new List<DataItem>();
for (var i = 0; i < npts; i++) {
count += _data[i];
_data1.Add(new DataItem {
Time = $"{i + 1}",
PDF = Math.Round(_data[i] / sum * 100, 2),
CDf = Math.Round(count / sum * 100, 2)
});
}
}
return _data1;
}
}
private void Flexchart_SymbolRendering(object? sender, RenderSymbolEventArgs e) {
e.Engine.SetFill(brushs[e.Index % 6]);
}
public class DataItem {
public string Time { get; set; }
public double CDf { get; set; }
public double PDF { get; set; }
}
} 这个看不出来,请上传一个重现问题的demo,我来帮你看一下原因 Richard.Ma 发表于 2022-5-10 17:10
这个看不出来,请上传一个重现问题的demo,我来帮你看一下原因
demo一直没上传成功,我把代码直接回复在评论里了。一个xaml,一个xaml.cs 好的,我明天早上验证后给你回复 Richard.Ma 发表于 2022-5-10 17:59
好的,我明天早上验证后给你回复
这是C1的版本
好的,你直接贴上来的代码有些会被转义,这边报错较多,麻烦还是上传一个cs代码文件上来 Richard.Ma 发表于 2022-5-11 09:47
好的,你直接贴上来的代码有些会被转义,这边报错较多,麻烦还是上传一个cs代码文件上来
网络限制了文件上传:'( 我试了下,通过点击复制代码确实会有问题,全部选中再Ctrl C进行复制是ok的
页:
[1]
2