1

I am using Microsoft's D3 with WPF (not silverlight). I am desperately looking for a version of D3 that would allow ,me to hide the legend. I found several examples online, using older versions of D3. When adding the sources of this version to my solution, I lost other functionality I was using - plotting a graph with logarithmic scales. Another version of D3 that was used in an example of a logarithmic scale did not have "hide legend" implemented yet. Apparently, the examples I've seen used different versions that are mutually exclusive. Moreover, I am not enough savvi with c# to take one version and convert it to the other.

Would you guys please please please help me and provide a solution that uses any (preferably latest) version of D3 for WPF that makes a ChartPlotter with logarithmic scale and is able to hide the legend?

Thanks

Gabe
  • 630
  • 1
  • 9
  • 25
  • What version of D3 are you currently using to use logarithmic scales? If you can provide me with the version you're using I might be able to tell you how to implement and/or use the hiding of a legend. The most recommended version of D3 to use is the stable version from http://dynamicdatadisplay.codeplex.com/releases/view/26761 – Jason Higgins Nov 09 '12 at 14:56
  • 1
    Jason Higgins - First and foremost, thanks. I am using the example here - http://dynamicdatadisplay.codeplex.com/Project/Download/AttachmentDownload.ashx?ProjectName=dynamicdatadisplay&WorkItemId=10297&FileAttachmentId=3189. As to the latest version, I beg to differ - http://dynamicdatadisplay.codeplex.com/sourcecontrol/list/changesets?ProjectName=dynamicdatadisplay. – Gabe Nov 10 '12 at 08:13
  • Thanks, all the information and examples I have on D3 are at work, so I will get back to you on monday with an answer! :) Hope you can hold out until then! – Jason Higgins Nov 10 '12 at 22:27
  • Jason Higgins - Currently using ugly and messy workarounds - the version that allows the logarithmic scale and setting plotter.legend.Content = Null. That's not playing nice. Moreover, since it's an older version, it's slower... Will wait till Monday. Thanks again. – Gabe Nov 11 '12 at 05:25

1 Answers1

1

The key to this seems to be the LogarithmNumericTicksProvider class. This class alone seems to give you the functionality you need. So you could take that class and import it to the version of D3 you have that has a hiding legend working.

Your other option, would be to take the most recent stable version of D3, and fix the legend hiding in it. The solution that I found for hiding the legend does not seem to yet be implemented in the stable version, but looks very easy to.

You can add a new property to the ChartPlotter class for Legend Visibility that should hide and show your legend when setting the property. It looks like this :

class ChartPlotter {
...
public bool LegendVisible {
  get { return legend.Visibility == Visibility.Visible; }

  set { legend.Visibility = value ? Visibility.Visible : Visibility.Hidden; }

}
}

With this, you can set the LegendVisible property to true or false anywhere you need to in your code and it should show or hide on command. I found this solution Here

The most stable version of D3 can be found Here. This version implements the LogarithmNumericTicksProvider. This version is the most suitable to use and should be easy to implement the new property.

Jason Higgins
  • 1,516
  • 1
  • 17
  • 37
  • Not a problem! Good luck on the rest of your project :) – Jason Higgins Nov 12 '12 at 15:09
  • Jason, would it be too much to ask for a sample D3 solution with the logarithmic scale implemented? – Gabe Nov 13 '12 at 12:24
  • Hmm, I could give it a go if I have some extra time today! I'll keep you posted! – Jason Higgins Nov 13 '12 at 14:05
  • 1
    Here is the project that I have created for you : http://sdrv.ms/TXL2YS You will need to log in with your microsoft account( Outlook ) I think to access it. I used the most recent build from the source code, and added in the example you are using as a test. Upon first glance, there was TWO legends showing, but I was able to hide them both. Legend A was hidden using the solution I described above with the new Property, Legend B was hidden using plotter.NewLegendVisible = false; You can see both of these set in the Window1_Loaded method in the example. Hope this helps! – Jason Higgins Nov 13 '12 at 15:24
  • Thanks. I now this took you precious time. Appreciate it. – Gabe Nov 13 '12 at 16:40