Dashboard using highcharts.js - highcharts

I'm trying to build a dashboard using highcharts.js(multiple charts are displayed on a page), the data for these charts are fetched via ajax. Each of these charts can be refreshed independently. Initially when I was trying to get this working I was getting error #16 and I figured out that HighCharts.js was included and the ajax response was sending back HighCharts again and hence this error was being thrown by HighCharts.
To circumvent this I added js code to check if HighCharts was already defined and if it was I set it to null
if(window.Highcharts){
window.Highcharts = null;
}
This seemed to solve the problem, but however I now see that when I refresh one chart the other chart(s) on the dashboard seem to have some rendering issues - a part of the other chart(s) seems to have been stripped off.
Please let me know if what I'm doing is right, also please let me know a better way in which I can avoid loading HighCharts is its already loaded.

Assuming you have control over the HTML you're rendering, you need to do either;
Place highcharts (and other scripts) as a dependency in the page container so that you're sure it loads only once.
Conditionally load HighCharts dynamically rather than statically.
Eg something like this;
function buildChart(func) {
if (window.Highcharts === undefined) {
console.log("Highcharts is not loaded, fetching...");
$.getScript("http://code.highcharts.com/highcharts.js", function () {
alert("HighCharts was loaded");
func(); // build chart
});
}
else {
console.log("HighCharts was already loaded");
func(); // build chart
}
}
// test
buildChart(function () {
// build chart
console.log("Read to build chart with:", window.Highcharts);
})
However, this simple example doesn't cater for concurrent requests whilst highcharts is still being loaded. So for conditional loading like this, I would look into using a library like RequireJS, YepNope or HeadJS which can handle these dependencies for you. You are then able to include the HighCharts script in your components as often as you like and they'll only be loaded once.

Why are you loading highcharts with each span? You only need to load it once when the document loads.
Highcharts does not need to load each time a chart is refreshed...it's already there.
All you need to do to refresh individual charts via ajax is return a json object of the data for that chart, and re initialize the chart with the existing options that were set when the page loaded.

Related

Highcharts - how to export chart with different scale in one click

I am trying to download one chart with different scales in one click.
I have an array of scales and I loop over them and export chart each iteration with corresponding scale. However, chart gets downloaded once and scaled by 3 which is the last element of the scales array.
const scales = [1,2,3];
const exportChart = (scale) => chart.exportChart({scale});
$('button.export').click( function () {
scales.forEach(exportChart)
});
I assume I'm not allowed to export chart multiple times. Appreciate if someone can help me with that. Thanks!
Here is my fiddle https://jsfiddle.net/sabira/bf6yLcxw/
You can export and save separately multiple charts by clicking on a button. The reason why you get only one image is because you're trying to send multiple requests to the server at once, therefore only one success and the rest are canceled. Instead of sending POST requests to the server you can use the offline exporting module's method, exportChartLocal which does all the export stuff locally. I have prepared a simple example which can be found below.
Example:
https://jsfiddle.net/BlackLabel/w5boxq13/

Tooltips sometimes appear empty under splite-plot-bands highcharts

I'm testint information from a page with Selenium Webdriver. I have a graphic like this: https://www.highcharts.com/demo/spline-plot-bands
and I'm having a problem when I try to get the info inside of every dot.
You have to know that this type of highcharts, every dot has the same xpath so, it's impossible to reach to different dots. I can only get one info in one dot.
//Click on toolip
WebElement element = driver.findElement(By.xpath(dot));
// action class to click
Actions action = new Actions((WebDriver) driver); action.click(element).build().perform();
String toolTipText = driver.findElement(By.xpath(tooltip)).getText(); if(!toolTipText.contains(example))
sb.append("===> Content error");
The problem is that ramdomly, I get empty info from that tooltips. Sometimes I correctly get the info but sometimes it appears empty. Why? Will it be problem because json call? I don't know what could I do...do you have any ideas?
Thanks so much in advance guys!!
I think you are looking wrong way at highcharts, please refer this highchart docs. Highchart is chart plugin that auto render HTML SVG based on highchart options.
To understand problem with tooltip information, you need to look into highchart series data, point objects. point object is contains information related to each dot in chart.

Multiple-page print or Reporting library for Vaadin 7 UI

We had a Vaadin 7 UI page with multiple Layouts, Panels, and Chart (the Browser will come with ScrollBar as height is big). When we try to print using JavaScript in Vaadin code or using Ctrl+P of browser, it prints only One page in Firefox 32.0.3; prints multiple pages with only data for First Page in IE 8.
We tried with specifying undefined size for all components in UI page
(as mentioned in https://vaadin.com/forum#!/thread/3869543/7861633)
We also tried with some CSS changes for print (as mentioned in https://vaadin.com/forum/#!/thread/529738/539201)
Both above cases didnot solved our problem. As we can understand from documentation that Vaadin scrolling uses a DOM structure, it was unusual to know such a tool does not provide proper Print option.
To brief our objective, we are looking at Reporting option in Vaadin for some data analysis. We saw some options (using JasperReport etc.) mentioned in StackOverflow, however will not be able to implement them as we need to deploy this application to Google App Engine (GAE) which has unsupported functions such as FileOutputStream etc.
To conclude, these are our issues -
How to resolve multiple page print issue in Vaadin 7?
If we are not able to solve first issue, What is the best Reporting library (for PDF or PNG or HTML or Print) that is supported by both Vaadin 7 and GAE?
Any guidelines or suggestions to direct us would be appreciated.
Printing HTML pages is random at best.
Every browser has it's own rules for display and page breaks. We always use pdf for things to print.
iReport / Jasperreports is the thing we use most of the time
You can try this workaround:
private void setSizeUndefined2Print()
{
com.vaadin.ui.JavaScript.getCurrent().execute("document.body.style.overflow = \"auto\";" +
"document.body.style.height = \"auto\"");
UI.getCurrent().setSizeUndefined();
this.setSizeUndefined();
}
If for some cases you need to switch back to "defined" size, next method can be used:
private void setSizeFull2Print()
{
com.vaadin.ui.JavaScript.getCurrent().execute("document.body.style.overflow = \"\";" +
"document.body.style.height = \"\"");
UI.getCurrent().setSizeFull();
this.setSizeFull();
}

ToolTip Performance in XPages

I have a large XPage with about 170 fields on it. I have tooltips for a fair number of the fields. The tooltip does a lookup into a help DB and returns the related text. They work fine but they significantly slow down the load process because of the number of times the lookup is performed. I put a dBar.info statement in the JS that loads the text and in one load the document and put it into edit mode it would appear to have fired that one tooltip lookup 6 times. If it does that for every one of the tooltips then clearly that is the reason for the slow performance of the XPage. I did it both with the DynamicContent set to both true and false with similar results. I'm tempted to just remove the tool tips but that kind of defeats the purpose.
Is there a way to limit the tooltip to only fire the lookup when called? Like something linked to the MouseOver event. It seems to me the tooltip in the extension Library works OK if there are only a few fields requiring inline help but does not scale well.
Just as a test I removed all the tooltips from the XPage and while the loading is slow it is probably acceptable, but the tooltips slow it to the point of unacceptability.
Bill,
This is an excellent use case for an ApplicationScope bean. Create a bean that implements Map and uses an internal HashMap as cache. Let's call it tooltip. In your tooltip you define the label as EL e.g. tooltip['Manager']. XPages will call the get function. In it you check the internal HashMap if you have the value, otherwise you look it up. So lookup happens once only.
You could instead of looking up on demand opt for loading when initialized. Using a view navigator that should be very fast. Since it would be an Application scope only loaded once.
Makes sense?
You can use view.isRenderingPhase() to minimise the lookups during a partial refresh. With the tooltip you can also change the showDelay property so the tooltip has a delay before showing. This is a good thing to do for a view, so it doesn't try to load each tooltip as the mouse moves down the page. dynamicContent="true" may also mean it's not loaded with the page, but only when called - I haven't checked this so I'm not certain.

Modify dynamic info window code to work for image links?

I'm trying to modify this code example for dynamic info windows to work for images instead of text:
https://developers.google.com/fusiontables/docs/samples/change_infowindow_content
I know that I can use this:
text
to make the images come up as links that open a new page using the Fusion Table custom InfoWindow UI, but some of the cells in my Fusion Table have an image URL, and others are empty. I want the InfoWindow to leave out the image link if there is no URL in the cell. Since I can't code this using the Fusion Table UI, I was wondering if it is possible to use the Fusion Tables Layer in the Google Maps API and modify this section of code:
// If the delivery == yes, add content to the window
if (e.row['delivery'].value == 'yes') {
e.infoWindowHtml += "Delivers!";
}
to test for the image URL instead testing for "yes"?? I would like the InfoWindow to display the link to the image if it is there, and I would like the link to be left out if the cell is empty.
Here is a link to my Fusion Table:
https://www.google.com/fusiontables/DataSource?docid=15wosKAeHC0gcpU_N6UPbxPL09RrEBKlQNEaCmnU#map:id=3
I would like to test all cells in the "y2012" column.
Any ideas??
You can also use what we call dynamic templating for the info windows. This lets you Closure Template syntax in an info window, including exactly your case of leaving out empty fields.
This should work in a click event listener on the layer:
// If the y2012 != "", add open the picture
if (e.row['y2012'].value != '') {
window.open(e.row['y2012'].value);
}
example

Resources