I have a problem with PyQt/its Webview. The code that is bothering me should render a chart, but it doesn't. I am using the Highcharts framework and provide the data for the javascript function that renders the chart via Python. I also check whether the webview is ready because that was a previous error of mine. The code in question looks something like this:
command = ('loadPinch(' + str(random.sample(range(10000), 1000)) +
', ' + str(['2009', '01', '01']) + ');')
self.webview.page().mainFrame().evaluateJavaScript("""
var readyStateCheckInterval = setInterval(function() {
if(document.readyState === 'complete'){ """ +
command + """
clearInterval(readyStateCheckInterval);
}
}, 10);""")
loadPinch is a JavaScript function and looks similar to this(which in turn looks similar to a Highcharts example graph):
function loadPinch(data, date){
$('#container').highcharts({
chart: {
zoomType: 'x',
spacingRight: 20
},
title: {text: 'Twitter Trends'},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' :
'Pinch the chart to zoom in'
},
xAxis: {
type: 'datetime',
maxZoom: 10 * 24 * 3600000,
title: {text: null}
},
yAxis: {
title: {text: 'Occurence'}
},
tooltip: {shared: true},
legend: {enabled: false},
plotOptions: {
area: {
fillColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
lineWidth: 1,
marker: {enabled: false},
shadow: false,
states: {hover: {lineWidth: 1}},
threshold: null
}
},
series: [{
type: 'area',
name: 'Twitter Trend',
pointInterval: 24 * 3600 * 1000,
pointStart: Date.UTC(date[0], date[1], date[2]),
data: data
}]
});
};
I might tell you that if I print the command that I am handing evaluateJavaScript to the console instead of executing it and pasting it over to the developer console, it gets executed as expected and renders the chart which leads me to believe that there is some sort of race condition I can't track down.
Does someone have an idea of what could be the problem?
Regards, Carson
NOTE: The problem is still relevant.