How to switch between 2 TimeSeriesCollection in the same JFreeChart - jfreechart

In my program I need to display a JFreeChart.
I'm adding, over time, series to that JFreeChart.
I'm having a tree who allows me to switch between different item and displaying them in the chart. What i do is that I update the TimeSeriesCollection. (Update or reset completely with new data)
But I need in a specific case to add data to one of my item, thus displaying the chart with the new data, and at the same time, the user might change item and the program still needs to update my 1st item while displaying the second.
Which mean i have a graph of "Item1" to which I'm adding data over time, and while doing that, i want to be able to switch to an "Item2" and displaying that item in the graph (while still adding my data to "item1")
I tough about using an other TimeSeriesCollections to wich i could put the new data while displaying the first TimeSeriesCollections. But i can't seem to find a way to switch between 2 TimeSeriesCollection.. like a myJFreeChart.setTimeSeriesCollection(TimesSeriesCollections tsc)
Any ideas?

As shown here, create your chart with a TimeSeriesCollection. As long as you have distinct TimeSeries instances, you can use removeSeries() and addSeries() to swap them as required. The ChangeListener will be adjusted accordingly. You can still add data to either series.
If you're still having problems, edit your question to include an sscce.

Related

Angular: moving charts into different bindings

New developer here working on some thing that's a little out of my depth.
I'd like to have dynamically generated charts into rotate into different, predetermined locations on my page.
for example:
chart 1
chart 2
chart 3
would rotate thru a list of 5 charts to display
chart 2
chart 3
chart 4
I feel like my best option here is to create objects (JSON maybe?) of these charts and to have them stored in an array, then have the array loop through the binding locations and 'plop' (for lack of better word) the object's details into the next spot in the rotation, which theoretically would allow the chart to render in the new location; with a timer driving the changes.
I would probably use pre-set frames to designate the slots being rotated into, though I'm less positive that is the right way to handle that.
I know this is possible with angular, and despite my best efforts I cannot for the life of me determine the best way to go about this. I'm really very open as to the method this gets done, but am at a complete loss on how to set up the data-binding framework to accomplish this.

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.

Sencha Charts Extending Columns outside of the view port

I'm working on getting familiar with Sencha charts. I'd like to know if there is any way that I can extend a column outside of the view port. For example I have data for which I have the min, first quartile, third quartile, and max for and I make a stacked chart out of these. However the max contains several outliers that probably won't be relevant to the user. What I want to do is end the view after the third quartile somewhere. Is there a simple and easy way to accomplish this?
You would have to work out the algorithm to get the percentage of records that go beyond your third quartile. That shouldn't be too hard.
Then create a function that set's the chart's width to a size which is equal to:
[viewport width] * (1 + [the percentage])
You can use the chart's setWidth method for this.
You can call this function in the chart's beforerefresh event (it should fire after the chart store data is loaded but before it is rendered on the chart) and also in the viewport's resize event.

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.

ExtJS 4 Chart - Change axes, series, and store

I have a chart that will show energy generation over a day, month, or year, depending on the user's selection. To do this on a single chart, I need to be able to change the axes, series, and store when a button is clicked. I have managed to get this working, except I have the issue of the old data, series, and axes are still showing, and the new ones are just being laid on top. Is there a way to clear or refresh/redraw a chart? Or should I just split this into 3 charts, and hide/show the charts on button click?
Here is my current code for setting axes, series and store on the fly.
chart.axes.clear();
chart.axes.addAll(dailyAxes);
chart.series.clear();
chart.series.addAll(dailySeries);
chart.bindStore(Ext.data.StoreManager.lookup('dailyEnergy'));
A little late, but what's missing is this:
chart.surface.removeAll()
This isn't ideal, as you may get a flash of empty space as it destroys the previous elements, but it does avoid the hangover of old data.
i dont know what type of chart or what is dailyAxes
but i assume u want to change axes properties..hee is an example on how to do it:
Ext.getCmp('chartid').axes.get("gauge").maximum = 100;
then u need to redraw the chart after ur done:
Ext.getCmp('chartid').redraw();

Resources