我的英语写得不好。
我正在使用具有线性系列趋势的 wpf 工具包。
我每天通过 linq 分钟从数据库中提取1001200...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 图表
<chartingToolkit:LinearAxis
x:Name="xAxis"
Orientation="X"
ShowGridLines="True"
Location="Bottom"
Title="Orario della lettura"
AxisLabelStyle="{StaticResource XAxisLabelStyle}"
>
在 CS 上
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();
}
}