URL for each box in stacked bar graph - graph

I want to create a stacked bar graph as in url below
(source: jpowered.com)
I want to make hyperlink for each of the red ,violet and blue boxes.The graph is possible with jfree chart but i don't know how to make each of the individual bars as URL so that a click on it can refresh the page.
Is it possible to do it with jfree chart?
Does Jquery plot help in this case to make each box url enabled ?Please suggest.

Using jfreechart, you can apply a CategoryURLGenerator to the plot using whichever of the two implementations better suits your needs. The approach is outlined here for the related PieURLGenerator. ChartFactory.createStackedBarChart() uses a StackedBarRenderer and allows PlotOrientation.HORIZONTAL.
Addendum: To generate URLs for individual items, you can examine the ChartEntity returned in a ChartMouseListener, as shown here.

I know that you can achieve something like this in jqPlot without much trouble.
The only think you need to remember, after you create your plot, is to bind your function to jqplotDataClick event. In your function you would need to map your clicks to a structure of urls. I have presented this in a sample example, where only the first series' bars take you to some websites. The sample is on jsfiddle --- it could be found here.
Effectively all comes down to this piece of code:
var urls = ["www.yahoo.com", "www.google.com", "www.java.com", "www.w3schools.com/js/js_obj_date.asp"];
$('#chart').bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
if(seriesIndex === 0){
var url = urls[pointIndex];
window.open("http://"+url);
}
});
EDIT
I do not know an easy way, i.e. that wouldn't involve changing the script of jqPlot, of identifying the clicked bar by highlighting its background. Though I figured out a way to get a similar effect by coloring background of point labels which are on bars, the code would also need to be in the jqplotDataClicked, something like:
var prevClicked;
var prevBackgroundColor;
$('#chart').bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
var str = ".jqplot-point-label.jqplot-series-"+seriesIndex+".jqplot-point-"+pointIndex;
$(str).each(function(){
if(prevClicked)
$(prevClicked).css('background-color', prevBackgroundColor);
prevClicked = this;
prevBackgroundColor = $(prevClicked).css('background-color');
$(prevClicked).css('background-color', 'red');
});
});
You just find the clicked point label using jQuery and apply your style, e.g. changing background color, remembering the previous label so you can remove its color to previous state on click on another bar. First I tried using addClass/removeClass functions but it didn't change a label's style, thus I had to use the css function instead.

Related

Holoviews - how to set legend click_policy for decimated points

I'm trying to set click_policy to 'hide' in legend_opts for the object resulted from applying holoviews.operation.decimate on a set of hv.Points, but it doesn't seem to have the desired effect.
Now I'm using the muted_alpha option on the underlying hv.Points to hide the points, but this is suboptimal, since hovering over the invisible points still shows the tooltip, which is cluttering the output when showing multiple curves.
I've tried passing legend_opts={'click_policy': 'hide'} as opts for the Overlay container, as well as for both the underlying hv.Points and for the result of decimate (actually, I also tried passing it as an argument to decimate), but to no avail.
I even tried using a hook for the bokeh plot as suggested here to directly set plot_obj.state.legend.click_policy = 'hide', but that doesn't work either.
So, any idea on how to hide a set of decimated hv.Points completely (i.e., not showing the hover tooltips either)?
Note: I've followed the "Principles of datashading" section of holoviews' user guide on "Working with large data" and used decimate as indicated there.
Turns out that one has to set the options for hv.Overlay after calling collate on it.

Adding tooltips in Gvis timeline through R

I'm looking for a solution in R (if possible) to add a custom tooltip content to a timeline chart built with the googlevis package in R.
Specifically, I have a dataset that looks as follows:
Content1 StartDate EndDate Content2 GroupingVariable GroupingVariable2
I can build the timeline out using the R package using the function gvisTimeline, but I want to know how I can build a custom tooltip for the timeline using the field content2.
The solutions I've seen involve changing the javascript code itself, which I am very unfamiliar with. The reason I am hesistant to do this is that the amount of different content I have would be very timeconsuimg to manually add to the JS code(hundreds of different content) - if I could create the vector in R and use that to populate the tooltip it would be viable.
Further, would it be possible to color the chart based on the a third variable as well?
I figured out a possible way to do this. In the bar label argument of timechart, if I pass an array of strings such as barlabel = c("Content1", "Content2.tooltip") it replaces the tooltip with the custom content. The column must end in the .tooltip for it to work.

Hide/show multiple graphs in qcustomplot

I am making a data logger for a couple of Arduino sensors in Qt. The problem is that I want to log the data in 3 different graphs, each of one having one specific scale, and then I'll choose what graph I will show (just one of the 3 graphs will be displayed at one time).
I tried something like this:
QCPGraph *sensorXGraph = ui->graph->addGraph();
QCPGraph *sensorYGraph = ui->graph->addGraph();
sensorXGraph->setVisible(false);
sensorYGraph->setVisible(false);
And then, in a slot call from a RadioButton clicked event I did:
sensorXGraph->setVisible(true);
sensorYGraph->setVisible(false);
And the inverse for another RadioButton. But the graph seems to keep the axis of the last graph created. So, if I try to see the sensorXGraph, the data will change accordingly but y axis range will be the one of the sensorYGraph.
I also tried to make a single QCPAxis for each graph, but it started to be a mess because I had to make QCPAxisRect for each graph as well and the result was worse than the first trial.
How do I achieve to change from one graph to another properly?
Thank you in advance.
You can call clearGraphs() on your QCustomPlot and then add whatever graphs you want to display by calling addGraph() and then call replot() on your QCustomPlot. So it would be something like this:
ui->graph->clearGraphs();
ui->graph->addGraph();
// Do whatever you need to do to edit your graph.
ui->graph->replot();
Since you are using a radio button I think that it would be easier to draw one graph and add the necessary data and labels based on whatever radio button has been selected. Hopefully that helps!

Bokeh Charts: Custom HoverTool variables for Bar Charts

If I make a bar chart like this:
bar = Bar(data,labels,tools='Hover')
I can make tooltips like this:
hover = bar.select(dict(type=HoverTool))
hover.tooltips = [
('Grade',' $x'),
('Students',' #Students'),
]
However, when I do variables with '#variable' in the tooltips, I am limited to those specified in data. In normal Bokeh plots, I can have custom variables associated with data points by using a ColumnDataSource. Bar does not support ColumnDataSources. Is there another way to make custom variables available in Bokeh chart tooltips (hover)?
There's is an open PR to add this feature to the charts interface.
It's going to be part of the next bokeh release and also be available through the dev builds (or in the master branch of course) as soon as it gets merged if you need it sooner.
I had the same problem. The trick here is to use GlyphRenderer to make the bar chart aware of the data source. For e.g., you can add a line
bar.select(dict(type=GlyphRenderer)) before hover = bar.select(dict(type=HoverTool)). You can then refer your custom variables using #cat, #zero etc. See the following link for more information and a working example.
https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/-aDPTqDPA3M

Invert horizon graphs in cubism

I am trying to get those cool network graphs I saw on the cubism.js presentation where the RX was upside down on top and the tx was normal below.
The fact is that the only way I seem to get the chart drawing upside down is doing metric.multiply(-1) but then the values are negative so its not exactly ideal.
Any hint?
In the absence of a nice way to do this, you can replace the horizon chart formatter with one that just emits absolute values. You can do something similar with comparison charts too.
Something like this works :
var horizon = cubism.context().horizon();
var existingFormatter = horizon.format(); // Obtain the format function
var absoluteFormatter = function(value) {
return existingFormatter(Math.abs(value));
};
horizon.format(absoluteFormatter);
This will have the effect of still rendering the charts as a "negative" but will allow you to render your values as desired.
Obviously, you can adopt according to your needs.

Resources