I created a ScatterSeries chart using the following:
public ScatterPlot()
{
InitializeComponent();
ScatterSeries a = new ScatterSeries();
a.Title = "Series A";
a.IndependentValuePath = "Key";
a.DependentValuePath = "Value";
scatterplot.Series.Add(a);
((ScatterSeries)scatterplot.Series[0]).ItemsSource = new KeyValuePair<DateTime, int>[]
{
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(1), 0),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(2), 150),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(3), 150),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(4), 0),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(5), 0),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(8), 130),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(9), 130),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(10), 0),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(11), 0),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(15), 225),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(16), 225),
new KeyValuePair<DateTime, int>(DateTime.Now.AddMonths(17), 0)
};
}
I have a dictionary where every data point is mapped to a separate text label. I was wondering if it is possible to establish a binding such that when I move my mouse over a point, I get the text label instead of the actual number? Any suggestions on how to do this?
Set the
DataPointstyle …but the trigger based tooltip setter didnt work when I tested. The event setter worked though. So quickest fix could be to use that event setter and set the
TooltipService.ToolTipfrom code behind in the handler.But if you are using MVVM then you could use some attached behavior to handle this event and set the tooltip explicitly.
OR
You could override the
ScatterDataPointtemplate using the above Style and just set template to thisNewTemplate…Notice that in the
ControlTemplatebelow I have set theToolTipService.ToolTipto the Tooltip of the DataPoint. So you will have to use the above style to set theTemplateand theToolTip…