2

Using WPF (not Silverlight) D3, is it possible to put strings on the Y axis? I am specifically talking about a situation in which I have a graph of a timeline with status values (let's say "High" and "Medium" and "Low" mapped as 1, 0 and -1) and want the status on the y axis ticks instead of the numbers...

Thanks!

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Gabe
  • 630
  • 1
  • 9
  • 25

2 Answers2

3

You can use a LabelProvider to achieve your desired effect. You will have to make a new LabelProvider class that stems off of either LabelProviderBase, or more specifically in your case, NumericLabelProviderBase. You should be able to take all the ticks you have (1,0-1) and change them into strings using an if or a switch in your new LabelProviderClass. There's tons of examples in the source of label providers you can use as a base.

The method you are looking to override is CreateLabels. Here is a quick method I whipped up that should (hopefully!) get you where you need to be. Implement in the new class you create.

public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) {            

        var ticks = ticksInfo.Ticks;
        Init(ticks);            

        UIElement[] res = new UIElement[ticks.Length];
        LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info };
        for (int i = 0; i < res.Length; i++) {
            tickInfo.Tick = ticks[i];
            tickInfo.Index = i;
            string labelText = "";

            if(Convert.ToInt32(tickInfo.Tick) == 1) {
                labelText = "High";
            } else if(Convert.ToInt32(tickInfo.Tick) == 0) {
                labelText = "Medium"
            } else if(Convert.ToInt32(tickInfo.Tick) == -1) {
                labelText = "Low"
            } else {
                labelText = ""
            }

            TextBlock label = (TextBlock)GetResourceFromPool();
            if (label == null) {
                label = new TextBlock();
            }

            label.Text = labelText;
            label.ToolTip = ticks[i].ToString();

            res[i] = label;

            ApplyCustomView(tickInfo, label);
        }
        return res;
    }

To assign this new LabelProvider to a ChartPlotter, name the axis that you want to label in XAML or create it as an object in C# :

yAxis.LabelProvider = new ZazkapulskLabelProvider();
Jason Higgins
  • 1,516
  • 1
  • 17
  • 37
  • Jason, I should take you on retainer. Thanks again. Would you show me how to use this method in the definition of a plotter = new ChartPlotter? – Gabe Nov 14 '12 at 06:27
  • Jason, what's your address? Where to send the flowers to? BTW, have you seen this one - http://stackoverflow.com/questions/13378180/wpf-dynamicdatadisplay-slow-plotting-with-markers? – Gabe Nov 14 '12 at 14:19
  • Haha, no worries! I've been working with this library for a while and was sad to see there was no documentation. I'm glad to help people who had to go through the same struggle I did! As long as you accept the answer and possible throw some upvotes, I'm happy ;) – Jason Higgins Nov 14 '12 at 14:21
0

Dont use upper solution. Make my VS many compiler errors. I'm trying that solution on VS2013 on 3 hours but didnt work. Use that solution wherein function draw graph :

 dimSeviyesiAxis.LabelProvider.CustomFormatter = (tickInfo) =>
        {
            return "%" + tickInfo.Tick.ToString();
        };

Which dimSeviyesiAxis is xaml axis name made the axis label starts with "%". Before return you can code any conditional statements. Here is the source link :

http://dynamicdatadisplay.codeplex.com/discussions/462842

Tarık Özgün Güner
  • 1,051
  • 10
  • 10