Reputation: 25
I'm using dynamicdatadisplay library for WPF! not SilverLight
I've finish my backend codding already and stuck with graph.
I have an X-Axis that is a DateTime (hours).
Also I Have an Y-Axis that is Decimal.
But I can't find how to put between this axes custom marker (or whatever) which will be a dynamic string.
For example in 10 hours 03.11.2013 (x-axis) the price of the Stock was 120$ (y-axis) but in graph (in the cross of the axes) it must be a string "Volume: 50" which will show how much stocks was sell.
How to make it in code? Please give me some examples or advice.
Now my project look's like this:
========= 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>
=============================================
================ MainWindow.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;
}
}
Upvotes: 0
Views: 1585
Reputation: 89
// 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));
Upvotes: 1