C# 图表Wpf工具包处理程序图形标签
我英语写得不好 我正在使用wpf工具包和linearserie trend 我每天通过linq从数据库中提取几分钟 100 1200 ... 1300 并在x轴的图形上显示它们 我想将此值转换为小时 小时:分钟=1200*60+“:”1200%60 向他们展示x轴 有大量数据时的问题和图形 很难看到,所以我应该使用 xAxis.Interval=sliderIntervalloX.Value 它适用于LineSeries(但对于DateTimeSerie来说太慢) 然后我会截取x上的文字,并写出标签的值 用我上面写的公式C# 图表Wpf工具包处理程序图形标签,c#,wpf,C#,Wpf,我英语写得不好 我正在使用wpf工具包和linearserie trend 我每天通过linq从数据库中提取几分钟 100 1200 ... 1300 并在x轴的图形上显示它们 我想将此值转换为小时 小时:分钟=1200*60+“:”1200%60 向他们展示x轴 有大量数据时的问题和图形 很难看到,所以我应该使用 xAxis.Interval=sliderIntervalloX.Value 它适用于LineSeries(但对于DateTimeSerie来说太慢) 然后我会截取x上的文字,并写
<charting:Chart Name="GraficoTemperatura"
HorizontalAlignment="Left" Title="Grafico temperatura"
VerticalAlignment="Top" Background="#FF4CAE78" Height="231.25" Width="576.25">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis
x:Name="xAxis"
Orientation="X"
ShowGridLines="True"
Location="Bottom"
Title="Minuto della lettura"
>
</chartingToolkit:LinearAxis>
<charting:LineSeries
DependentValuePath="Value"
IndependentValuePath="Key"
ItemsSource="{Binding}" Title="Temperatura (°C)" AnimationSequence="FirstToLast" >
<!-- style della linea -->
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="{x:Type chartingToolkit:LineDataPoint}">
<Setter Property="Background" Value="Red"/>
<Setter Property="Visibility" Value="Collapsed"/>
<Setter Property="Template" Value="{x:Null}"/>
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
</charting:LineSeries>
</charting:Chart>
解决方案
xaml资源
<local:RatingToStringConverter x:Key="RatingToStringConverter"/>
<Style x:Key="XAxisLabelStyle" TargetType="chartingToolkit:AxisLabel">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:AxisLabel">
<!-- <TextBlock Text="{Binding Label, Converter=}"/> -->
<TextBlock Text="{Binding Converter={StaticResource RatingToStringConverter}}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的英语写得不好
-XAML是所有WPF开发人员相互交流和理解的通用语言。发布你当前的XAML。我通过输入代码编辑了帖子,谢谢!!!粘贴代码
<chartingToolkit:LinearAxis
x:Name="xAxis"
Orientation="X"
ShowGridLines="True"
Location="Bottom"
Title="Orario della lettura"
AxisLabelStyle="{StaticResource XAxisLabelStyle}"
>
public class RatingToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// Validate parameters
/*if (!(value is double))
{
throw new NotSupportedException("Unsupported value type in RatingToStringConverter.");
}
*/
// Convert number to string
//int idoubleValue = Math.Ceiling ((double)value);
int doubleValue = System.Convert.ToInt32(value);
//int doubleValue = (int)value;
string a = (doubleValue / 60).ToString();
string b = (doubleValue % 60).ToString();
return a + ":" + b;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}