原创:DynamicDataDisplay 原版本在日期显示的格式上与我们的习惯不一样,特做如下修改:
自定义日期格式修改:
//MainWindow.cs中
var ds = new EnumerableDataSource<VoltagePoint>(voltagePointCollection);
ds.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
ds.SetYMapping(y => y.Voltage);
plotter.AddLineGraph(ds, Colors.Green, 2, "Temperature"); // to use this method you need "using Microsoft.Research.DynamicDataDisplay;"
MaxVoltage = 40;
MinVoltage = 0;
plotter.AxisGrid.BorderBrush = new SolidColorBrush(Color.FromRgb(50,50,0));
dateAxis.LabelProvider.LabelStringFormat = "HH:mm:ss"; cursorCoordinateGraph.XTextMapping = x =>
{
if (Double.IsNaN(x))
return ""; DateTime time = dateAxis.ConvertFromDouble(x);
return time.ToString("HH:mm:ss");
}; LabelProviderBase.cs: protected virtual string GetString(LabelTickInfo<T> tickInfo)
{
string text = null;
if (CustomFormatter != null)
{
text = CustomFormatter(tickInfo);
}
if (text == null)
{
text = GetStringCore(tickInfo); if (text == null)
throw new ArgumentNullException(Properties.Resources.TextOfTickShouldNotBeNull);
}
if (LabelStringFormat != null && LabelStringFormat.Length > 0)
{
//text = String.Format(LabelStringFormat, text);
if (tickInfo.Tick is System.DateTime)
{
text = Convert.ToDateTime(tickInfo.Tick).ToString(LabelStringFormat);
}
else
{
text = String.Format(LabelStringFormat, tickInfo.Tick);
}
} return text;
}
修改底下的标签: