Using JFreeChart Scatter Plots is there a Way to Subdivide Styles for Data Sets? - jfreechart

I am using JFreeChart to render a scatter plot with a couple thousand data points. I control the appearance/style of each ScatterPlotDataset by attaching a suitable XYLineAndShapeRendererper to each data set; eg. points in data set 1 appear as circles and points in data set 2 appear as squares. I would like the user to be able to dynamically assign a sub-style per point in each data set; eg. if the data set were books then the user might wish to color fiction blue and nonfiction red. Is there a way to do this without defining a new data set for each sub style?
Incidentally I am carting with XYPlot but I can switch to another chart type if necessary.
Thank you in advance.

You might consider the approaches mentioned here. The first implements DrawingSupplier, as shown here:
class DefaultDrawingSupplier implements DrawingSupplier…
The second extends DefaultDrawingSupplier, as shown here, to achieve a similar effect.
Paint[] paintArray = {…};
plot.setDrawingSupplier(new DefaultDrawingSupplier(
paintArray, …
DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
Of course, you can always override getItemPaint(), as shown here.

Related

How can I display fewer labels on the X-axis when it is an instance of CategoryAxis? (JFreeChart library)

I have a CategoryAxis used with a BarChart where I have too many labels to be readable.
I would like to set a visible interval for the labels, so let's say each ten values the label is printed.
I read some posts where setTickUnit() method is recommended, but such method doesn't exist in CategoryAxis.
Here you can see a sample of what I am referring to, as you see I have tens of dates so you can't read them:
Any pointer or recommendation?
Thanks!
You can find a pretty good explanation of the problem (and some solutions) in the FAQ section of the JFreeChart homepage.
You might be better of with an XYPlot and an XYBarRenderer.

Draw a vertical line on Left Click MouseDownEvent

I'm using the Oxyplot library to plot some graphs based on real-time data. I know there is a feature called Tracker that shows some tooltip-like information (coordinates, for example) based on the Position where the user left-clicks. The information is only shown while the left-button is pressed.
I'm currently testing this functionality on a line graph, not sure if it works for other types.
What I wanted to do is to keep this info on screen and making it disapper only if the user tries to set a new one, clicking somewhere else on the graph and replacing the older information. Adding a vertical bar where the user clicked would be nice too.
I checked the Oxyplot documentation and I know that it is possible to customize this 'Tracker', but I failed to find a solution for my situation.
EDIT:
I've found this example, it seems helpful, but I'm struggling to extract the usefulness of it. Please help!
UPDATE:
Let me go a little further on the explanation of what I'm trying to achieve. I have many graphs, each of them placed on a separated panel (or tab). If I left-click in a position of a graph, I want to show the Tracker info on that specific position on each and every graph while the user doesn't click on another position (setting a new Tracker and removing the old one). In other words, it is allowed one Tracker at a time, and this is set on every existing graph at the same X-position.
UPDATE 2:
Alright, so after giving it a thought, I decided not to maintain the Tracker when left-clicking. Instead, I just want to draw a vertical line on every graph on the position of the click. Just one line at a time is permitted, it can be treated as a "temporary marker". I believe this is more doable than the other approach and will suffice my needs.
You can unbind the left button and replace it by just hovering the mouse, almost always showing the tracker:
public PlotController customController { get; private set; }
customController = new PlotController();
customController.UnbindMouseDown(OxyMouseButton.Left);
customController.BindMouseEnter(PlotCommands.HoverSnapTrack);
Xaml:
<oxy:PlotView Controller="{Binding customController}"/>
EDIT >>>>>>
TrackerManipulator code: https://github.com/ylatuya/oxyplot/blob/master/Source/OxyPlot/Manipulators/TrackerManipulator.cs
I think you should create a custom TrackerManipulator, and override the Complete method to not to do the "this.PlotControl.HideTracker();" line.

Initialize JFreeChart range axis values

I am trying to load dataset during initialization of the JFreeChart. But every time I tried to create a dataset with higher "number of item per series", the more data (all data) displayed visible in the chart (the bigger the dataset, the smaller the graph). But actually what I wanted is to have the fixed range of dataset values displayed on the chart while the rest is still hidden. Just the same way the data would normally be displayed in the actual trading platform, let's say Metatrader (MT4). First time when I open the chart I can see the screen filled with the only visible dataset of the chart and if I left-scroll the chart I will be able to see the old/history dataset as well. Does anyone have idea how to achieve this using JFreechart?
Really appreciate for any help or any thing/articles I can refer. Thanks so much!
You can use setRange() on either the domain or range axis, as shown in this fragment. If you've already tried this, it may help to edit your question to include an sscce and/or image that exhibits any problems you encountered.

I want to graph enumeration values (by their integer values) but have strings displayed in Silverlight Toolkit Chart control

In our application we allow users to chart enum values over time. We want the values plotted on the y-axis according to their integer values. However, we want the y-axis labelled with localized strings. And we'd like the "tooltip" diplayed when you hover over a plotted point to display a localized string.
I thought this would be "simple" since the Chart Control apparently will graph any IComparable data. So I created an EnumValue class that implements IComparable (based on int value) but that has a property named Value (used for binding) that is of type String.
So I thought I had been very clever and attempted to graph my EnumValues. When trying to display the graph of EnumValues I was told that the Chart control could not find a suitable axis to display the data. This makes sense as my data can't be plotted with the default LinearAxis. (I mean where would it plot the value "Off").
My question, is their a simple way to do this (like providing a map from int values to strings that the chart will automagically use), or will I have to define my own subclass of RangeAxis (or DisplayAxis) that tells the Chart how to plot these EnumValues.
I think creating the EnumAxis wouldn't be too hard, but their isn't a lot of documentation on what the methods need to do. (although you can gather a lot of info by looking at the other implementations).
Note, I'm currently trying to do this with Silverlight Toolkit Chart Control. But am evaluating Telerik and Software FX as well.
I did get this to work by creating my own Axis subclass.

Check for overlapping shapes in WPF

I have a set of shapes which need to be drawn on top of each other. I need to re-order them such that the smallest shape gets drawn last (i.e. it will be closest to the user). Is there any way to check whether a shape overlappes (encloses and/or intersects) another shape. I know there is a method in Rect structure called Contains which checks whether there is an object within it. Is there a similar method or a way to simulate it on Shapes in WPF? Thanks in advance for any help.
Cheers,
Nilu
You could probably use the Geometry.FillContainsWithDetail method. Its name is ill-chosen IMHO, but the description is clear :
Returns a value that describes the intersection between the current geometry and the specified geometry.
I have successfully used it for collision testing before, so it should work for you too...

Resources