大家好,我在将数据(日期和值(转换为图形曲线的项目中工作。 我对双格式的日期打印值的 X 轴有问题,我希望这个值像这样显示 14:12:35
var gradientBrush = new LinearGradientBrush
{
StartPoint = new System.Windows.Point(0, 0),
EndPoint = new System.Windows.Point(0, 1)
};
gradientBrush.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromRgb(33, 148, 241), 0.2));
gradientBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 1));
cartesianChart1.Series.Add(new LineSeries
{
Values = GetData(),
Fill = gradientBrush,
StrokeThickness = 0.9,
PointGeometry = null
});
cartesianChart1.Zoom = ZoomingOptions.X;
private ChartValues<DateTimePoint> GetData()
{
var values = new ChartValues<DateTimePoint>();
for (var i = 0; i <lsTemp.Count(); i++)
{
// System.DateTime.Today.AddDays(i)
values.Add(new DateTimePoint(lsDataTime[i], lsTemp[i]));
}
return values;
}
在此处输入图像描述
您需要设置 Axis 类的 LabelFormatter 属性。 像这样:
AxisX = new Axis
{
Title = "Date",
Separator = new Separator { IsEnabled = false,Step = 1 },
LabelsRotation = -90,
Foreground = new SolidColorBrush(Colors.Black),
LabelFormatter = value => new System.DateTime((long)value).ToString("t")
};
并查看此链接以获取格式ToString数据格式