动态数据显示 (WPF) 如何制作字符串标记



我正在使用 WPF 的动态数据显示库!不是银光

我已经完成了我的后端溺爱并坚持使用图形。

我有一个 X 轴,它是日期时间(小时)。

我还有一个十进制的 y 轴。

但是我找不到如何在此轴之间放置自定义标记(或其他什么),这将是一个动态字符串。

例如,在 10 小时内 03.11.2013(x 轴),股票的价格为 120 美元(y 轴),但在图表(轴的十字)中,它必须是一个字符串"交易量:50",这将显示卖出了多少股票。

如何在代码中制作它?请给我一些例子或建议。

现在我的项目看起来像这样:

=========

XAML =

=========

    <d3:ChartPlotter Name="plotter" Margin="20,20,20,70">
        <d3:ChartPlotter.HorizontalAxis>
            <d3:HorizontalDateTimeAxis Name="xAxis"/>
        </d3:ChartPlotter.HorizontalAxis>
        <d3:ChartPlotter.VerticalAxis>
            <d3:VerticalIntegerAxis Name="yAxis"/>
        </d3:ChartPlotter.VerticalAxis>
    </d3:ChartPlotter>
    <Button Content="Button" HorizontalAlignment="Left" Margin="254,364,0,0" VerticalAlignment="Top" Width="145" Height="46" Click="Button_Click_1"/>
</Grid>

====

===============================================================

主窗口.cs ===

===============
private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        List<DataForChart> dataForChart = new List<DataForChart>();
        dataForChart.Add(new DataForChart(new DateTime(2013, 11, 03, 22, 10, 0), 45));
        dataForChart.Add(new DataForChart(new DateTime(2013, 11, 03, 22, 20, 0), 48));
        dataForChart.Add(new DataForChart(new DateTime(2013, 11, 03, 22, 30, 0), 24));
        DateTime[] dates = new DateTime[dataForChart.Count];
        int[] price = new int[dataForChart.Count];
        for (int i = 0; i < dataForChart.Count; ++i)
        {
            dates[i] = dataForChart[i].date;
            price[i] = dataForChart[i].price;
        }
        var datesDataSource = new EnumerableDataSource<DateTime>(dates);
        datesDataSource.SetXMapping(x => xAxis.ConvertToDouble(x));
        var numberOpenDataSource = new EnumerableDataSource<int>(price);
        numberOpenDataSource.SetYMapping(y => y);
        CompositeDataSource compositeDataSource1 = new
        CompositeDataSource(datesDataSource, numberOpenDataSource);
        plotter.AddLineGraph(compositeDataSource1,
          new Pen(Brushes.Blue, 2),
          new CirclePointMarker { Size = 10.0, Fill = Brushes.Blue },
          new PenDescription("Price Chart"));
        plotter.Viewport.FitToView();
    }
    public class DataForChart
    {
        public DateTime date;
        public int price;
        public DataForChart(DateTime Date, int Price)
        {
            date = Date;
            price = Price;
        }
    }
// Create a custom marker control as follows
// CustomMarker.xaml:
<d3:ViewportUIContainer x:Class="MyNamespace.CustomMarker"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:d3="clr-namespace:Microsoft.Research.DynamicDataDisplay.Charts;assembly=DynamicDataDisplay"
                    mc:Ignorable="d" >
   <Grid>
      <TextBlock Name="TxtBlk1" Text="Some Text" />
   </Grid>
</d3:ViewportUIContainer>
// Marker control code behind CustomMarker.cs
using System;
using System.Windows;
using System.Windows.Media;
namespace MyNamespace
{        
    public partial class CustomMarker : Microsoft.Research.DynamicDataDisplay.Charts.ViewportUIContainer 
    {
        public CustomMarker()
        {
            InitializeComponent();
        }
        public CustomMarker(Point position, string text, Color color) : this()
        {          
            Position = position;
            TxtBlk1.Text = text;
            TxtBlk1.Foreground = new SolidColorBrush(color);
        } 
    }
}

//In your mainwindow.cs
var position = new Point(x value, y value);
plotter.Children.Add(new CustomMarker(position, "Text", Colors.Black));

相关内容

  • 没有找到相关文章

最新更新