I have the following problem - I'm trying to create highstock graphic with zoom-in/zoom-out buttons, but something is wrong with the zooming. When i press the button most of the times the chart zooms to the correct time interval, however, after I press the button a couple more times, the chart starts to behave weird - the animations aren't correct or it doesn't zoom or it zooms to the wrong interval.
This is the zooming function:
var xAxis = graphic.xAxis[0];
var minimum = xAxis.dataMin;
var maximum = xAxis.dataMax;
var newMin = 0;
var newMax = 0;
//when zooming out
newMin = xAxis.min - 360000;
newMax = xAxis.max + 360000;
//when zooming in
//newMin = xAxis.min - 360000;
//newMax = xAxis.max + 360000;
if (newMin < minimum)
newMin = minimum;
if (newMax > maximum)
newMax = maximum;
if (newMin > newMax) {
alert("min bigger than max");
}
console.log("newMin: " + newMin + " newMax: " + newMax);
xAxis.setExtremes(newMin, newMax);
Here's a fiddle: http://jsfiddle.net/E5kth/3/
jquery - 1.6.4
jquery mousewheel - 3.1.6
highstock - 1.3.7
Thanks in advance ;]
EDIT:
Here is a NEW video with better explanations of the problem: https://www.dropbox.com/s/5x1k5b0lbtqw81u/highstock_ordinal-false_bug_converted.avi
for better quality - download the video, dropbox streaming is with low quality.
I prepared simple example how it should be done, http://jsfiddle.net/3vB5B/. It get range from chart and then reduce range on 24 hours.
$('#btn').click(function(){
var min = chart.xAxis[0].getExtremes().min,
max = chart.xAxis[0].getExtremes().max;
chart.xAxis[0].setExtremes((min + 12 * 3600 * 1000),(max - 12 * 3600 * 1000)); //12 hrs on min and 12hrs on max, summarised it is one day.
});
Related
In my model, I am saving results from numerous Parameter Variation runs in a Histogram Data object.
Here are my Histogram Data settings:
Number of intervals: 7
Value range:
Automatically detected
Initial Interval Size: 10
I then print out these results using the following :
//if final replication, write Histogram Data into Excel
if(getCurrentReplication() == lastReplication){
double intervalWidth = histogramData.getIntervalWidth();
int intervalQty = histogramData.getNumberOfIntervals();
for(int i = 0; i < intervalQty; i++){
traceln(intervalWidth*i + " " + histogramData.getPDF(i));
excelRecords.setCellValue(String.valueOf(intervalWidth*i) + " - " + String.valueOf(intervalWidth*(i+1)), 1, rowIndex, columnIndex);
excelRecords.setCellValue(histogramData.getPDF(i), 1, rowIndex, columnIndex+1);
rowIndex++;
}
}
Example of my intended results:
10 - 80%
20 - 10%
30 - 5%
40 - 2%
50...
60...
Actual results:
0.0 0.0
10.0 0.0
20.0 0.0
30.0 0.998782775272379
40.0 0.0011174522089635631
50.0 9.9772518657461E-5
60.0 0.0
Results after settings initial interval size to 0.1:
0.0 0.9974651710510558
4.0 0.001117719851502934
8.0 9.181270208774101E-4
12.0 2.3951139675062872E-4
16.0 1.5967426450041916E-4
20.0 9.979641531276197E-5
24.0 0.0
How would I go about obtaining my desired results? Am I fundamentally misunderstanding something about the HistogramData object?
Thank you for your help.
The function you are using (getPDF(i)) returns value for the interval in fractions (not in percentages). So, you have to multiply the value by 100 in order to get it as a percentage. As for histogram bars, model analyze the results, specified interval numbers and interval size. After that, it will build the respective number of bars that cover all results. In your case, intervals from 0 to 30 do not provide any results and bars are not presented (PDF here is 0.0).
I have created a spline real time chart where I want to show points at regular intervals.
Every point is an event taking place after one minute. However I am having a hard time trying to understand all the moving pieces:
the interval function on the highchart demo I referred updated every 1 second, I have made that 6000.
the dummy updating in the javascript just takes the latest time and appends it, is there supposed to be some delay introduced there?
the dummy initialization data in series has a for loop which again I could not understand. I understand that javascript produces a UNIX timestamp and its millisecond manipulation however the default code (again slightly modified from a highchart demo) runs from -9999 to 0 and multiples by a number.
I want to understand these parts and make sure that every time my x axis 'ticks' towards the right, I have a one minute gap and only one point on the graph.
PS: Please forgive any missing brackets, they might have been missed while posting the question, but I assure you that it isnt a problem.
Here is my code for series:
series: [{
type: 'spline',
name: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -9999; i <= 0; i += 1) {
data.push([
time + i * 60000,
Math.round(Math.random() * 100) + 10
]);
}
return data;
}())
}]
Here is my code for the chart:
chart: {
events: {
load: function () {
// Set up the updating
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100) + 10
series.addPoint([x, y], true, true);
}, 6000);
}
}
}
As to your questions:
If you want to have 1 minute data interval, you need to use 60000 value (60 * 1000), 6000 milliseconds is 6 seconds.
Current date in the interval function is taking every 6000 milliseconds, which causes gaps in the data every 6000 milliseconds.
That data initialization depends on subtracting multiples of six seconds from the current timestamp:
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -9999; i <= 0; i += 1) {
if (i === -500) {
console.log(time, i, 60000); // 1560941909847 + (-500 * 60000)
console.log(time + i * 60000); // 1560911909847
} else if (i === -499) {
console.log(time, i, 60000); // 1560941909847 + (-499 * 60000)
console.log(time + i * 60000); // 1560911969847
} else if (i === 0) {
console.log(time, i, 60000); // 1560941909847 + (0 * 60000)
console.log(time + i * 60000); // 1560941909847 = actual time
}
data.push([
time + i * 60000,
Math.round(Math.random() * 100) + 10
]);
}
return data;
}())
There is a peculiar issue i am facing when drawing live chart.
I am adding point to a series every 1 sec and shifting after 14 min.(Added shift condition (14 * 60 + 1)).
Navigator gets points from 1st series and shifts but becomes straight line beyond 14 min.
Navigator series data length also becomes 0.
But Navigator series option data displays right length.
Please find the image in below url
http://postimg.org/image/5xxxq65cn/
Could anyone provide any input on the same ?
function updateChart(data) {
var i, dateTime = new Date(data[0].TimeStamp), signalSeries, shift;
for (i = 0; i < data.length; i += 1) {
signalSeries = chart.get(data[i].Key);
if (signalSeries) {
shift = signalSeries.options.data.length > (14 * 60 + 1);
chart.get(data[i].Key).addPoint([dateTime.getTime(), data[i].Value], false, shift);
}
}
chart.redraw();
}
With Regards,
Tripati Patra
I have to make a series as shown in the image.
The Dates and the values are dynamically generating based on the user selection. The Time is in 24 hrs format. Please tell me how can i create the series for this. Also how to put the duration 1 hour for the time value.
Image for Reference:
In your series data you are using data: [Date.UTC(2012, 10, 01, 12,11,10)] you can simply change that to: data: [90 *60 * 1000] //For 90 Minute
Here is the LIVE DEMO
If you want to plot other series for other days then you should add categories in xAxies. for example for showing 3 days:
xAxis: {
categories: ['01/10/2012', '01/11/2012', '01/2/2012']
},
And in series-data use equal number of parameters as you have in your categories for 3 categories:
data: [ 50 *60 * 1000, 100 *60 * 1000, 50 *60 * 1000 ]
See the LIVE DEMO
Use formatter in tooltip to see a correct hour:minutes when you hover the series.
tooltip: {
formatter: function() {
var ms = this.y;
var x = ms / 1000;
var seconds = x % 60;
x = x / 60;
var minutes = x % 60;
x = x / 60;
var hours = parseInt(x % 24);
x = (x / 24);
var days = parseInt(x);
if(days == 0)
{
return '<b>' + this.series.name +'</b> ->' + this.x + '<br/>' + hours +':' + minutes;
} else {
return '<b>' + this.series.name +'</b><br/>' + days + ' Day ' + hours +':' + minutes;
}
}
},
See the LIVE DEMO
I have a slightly complicated problem with my line chart.
I manage to make dynamic line chart, so when the user will input some points, they will be drawn on the graph as a line.
Now, my problem here is to add the second line on the graph automatically, according to the inputted values and specific formula that will calculate the second values for the second line.
Let me illustrate what I mean… First it’s drawn one line based on the previously inputted values. Let’s say, user input these values 1.6, 3.9, 3.3, 4.0, 2.5, 2.8…
===============================
The second line needs to be drawn according to this formula, that will loop through the inputted values...
var interestRate1 = 3.5 + inputed_value1 + 0.5 * (inputed_value1 - 3),
interestRate2 = 3.5 + inputed_value2 + 0.5 * (inputed_value2 - 3),
interestRate2 = 3.5 + inputed_value3 + 0.5 * (inputed_value3 - 3), etc…
Eventually the formula will calculate my second values (4.4, 7.85, 6.95, 8, 5.75, 6.2) and this is the outcome that I want to be achieved…
http://img191.imageshack.us/img191/9606/0sfy.png
===============================
On clicking the button “Draw the graph” it needs to be drawn 2 lines, one that is originally inputted from the user, and the second that is calculated by my formula.
Refer to my code here
http://jsfiddle.net/97SRR/4/
(I don’t know why the graph in not showing, it was fine on my index.html file…)
Please help me with this, I will appreciate any ideas about my code.. I have been struggling with this for weeks :(
Here is where you create series:
var sample = {};
sample.name = 'Inflation';
sample.data = [1.6, 3.9, 3.3, 4.0, 2.5, 2.8];
series.push(sample);
So you need just to add one more series, for example:
function calc(data) {
var l = data.length,
ret = [];
for(var i = 0; i < l; i++) {
ret[i] = 3.5 + data[i] + 0.5 * (data[i] - 3);
}
return ret;
}
var sample = {};
sample.name = 'Inflation';
sample.data = [1.6, 3.9, 3.3, 4.0, 2.5, 2.8];
series.push(sample);
var calculated = {};
calculated.name = 'Math formula';
calculated.data = calc(sample.data); // [4.4, 7.85, 6.95, 8, 5.75, 6.2]; - calculated data
series.push(calculated);