Highchart multiple series with csv - highcharts

I want to create a chart like this page : http://www.sjc.com.vn/chart/mini2.php
Here is my data.csv.
2013-10-12 09:10;37.100;37.300
2013-10-11 16:01;37.250;37.350
2013-10-11 14:35;37.200;37.350
2013-10-11 11:08;37.150;37.350
2013-10-11 09:36;37.130;37.330
2013-10-11 09:18;37.150;37.350
2013-10-11 09:05;37.150;37.350
2013-10-10 17:30;37.340;37.410
2013-10-10 16:52;37.350;37.420
2013-10-10 16:32;37.360;37.430
2013-10-10 15:51;37.370;37.440
2013-10-10 14:34;37.380;37.450
2013-10-10 12:23;37.360;37.430
2013-10-10 11:48;37.360;37.430
2013-10-10 11:14;37.340;37.440
2013-10-10 09:53;37.330;37.430
2013-10-10 09:07;37.330;37.430
2013-10-09 17:12;37.400;37.500
2013-10-09 10:17;37.430;37.530
2013-10-09 09:04;37.450;37.550
2013-10-08 11:31;37.450;37.550
2013-10-08 09:47;37.450;37.550
2013-10-08 09:33;37.450;37.580
2013-10-08 09:06;37.450;37.600
2013-10-08 09:05;37.400;37.600
2013-10-07 15:22;37.400;37.500
2013-10-07 10:40;37.370;37.520
2013-10-07 09:16;37.400;37.550
2013-10-07 09:05;37.400;37.550
2013-10-05 09:13;37.300;37.500
2013-10-04 17:08;37.350;37.500
And here is what I wanna do with highchart :
http://jsfiddle.net/trantienit/s2axe/1/
$(function() {
var seriesOptions = [],
yAxisOptions = [],
seriesCounter = 0,
names = ['AAPL', 'GOOG'],
colors = Highcharts.getOptions().colors;
$.each(names, function(i, name) {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {
seriesOptions[i] = {
name: name,
data: data
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter++;
if (seriesCounter == names.length) {
createChart();
}
});
});
// create the chart when all data is loaded
function createChart() {
$('#container').highcharts('StockChart', {
rangeSelector: {
selected:2
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: seriesOptions
});
}
});
How do I merge those together?

In case when you have CSV, you cannot use JSON or getJSON function. You need to use $.get() and then parse your csv to prapre correct series structure. Morever dates should be splitted and transform into timestamps (i.e by Date.UTC()) format.
Related topic: http://www.highcharts.com/docs/working-with-data/preprocessing-data-from-a-file-csv-xml-json

Related

Highstock export csv based on data grouping (export-data module)

Currently, the export-data module exports all the series data rather than processedXData and processedYData. However, I grouped the series with dataGrouping and I'd like to export only the processed data.
I'm aware that this question has been asked before (Highstock export csv based on data grouping), but it was in the context of the former export-cvs plugin.
How to modify the 'getDataRows' function in the export-data module for including only the processed data?
Example -> fiddle
Highcharts.getJSON("https://cdn.jsdelivr.net/gh/highcharts/highcharts#v7.0.0/samples/data/usdeur.json",function (data) {
var chart = Highcharts.stockChart("container", {
series: [{
name: "The series",
data: data,
dataGrouping: {
force: true,
units: [["year", [1]]]
}
}
]
});
console.log(chart.getDataRows());
}
);

Slow query performance fetching keyword taxons in Spree extension

I'm working on adding functionality to an existing Spree custom photo printing store to allow photographers to upload their portfolios and sell photos through the site. I created a select2 text field for adding keywords to products using Spree::Taxon(s), and it works fine. I have fields for adding keywords in each language that the site supports (English and French).
However, the ajax query takes an extremely long time to complete (5-15s on average). The ActiveRecord query takes between 5-150ms to complete, and the view rendering takes no more than 60ms to complete. I can't account for the rest of the load time. Does anyone have advice on speeding up returning the result or what could be behind the extra time it takes to complete?
Using MySQL for the database, Ruby 2.2.1 and Rails 4.2.1. My dev environment is: Mac Mini (8gb ram, HDD), Aptana Studio IDE, server running on localhost:3000.
Please don't hesitate to request more clarifying information! I wasn't sure exactly what I needed to post to help with the context of my issue.
Controller to return JSON for the ajax request:
class KeywordTagsController < Spree::StoreController
respond_to :json
def find_keywords
term = params[:q]
Rails.logger.debug params.inspect
if params[:locale_str]
query = []
query = ["spree_taxons.name like ?", term + '%'] if term
locale = params[:locale_str].to_sym
keyword_taxonomy = Spree::Taxonomy.find_by(name: Spree.t("pi-taxonomy-keyword"))
keyword_taxons = keyword_taxonomy.taxons.with_translations(locale).where(query).order('name asc').select{ |t| t.parent_id != nil} if locale
respond_with keyword_taxons if keyword_taxons
end
end
end
Select2 initializer Javascript:
$("#keywords_en").select2({
createSearchChoice: function(term, data) {
if ($(data).filter(function() {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return {
id: term,
text: term
};
}
},
multiple: true,
ajax: {
url: '/keywords/en',
dataType: 'json',
data: function (params) {
return {
q: params // search term
};
},
results: function(data){
return { results: $.map( data, function (keyword, i) {
return {id: keyword.id, text: keyword.name }
})}
}
},
tags: true,
tokenSeparators: [','],
placeholder: '<%= Spree.t('pi-keywords-placeholder-en') %>',
initSelection: function (element, callback) {
var data = [];
function splitVal(string, separator) {
var val, i, l;
if (string === null || string.length < 1) return [];
val = string.split(separator);
for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
return val;
}
$(splitVal(element.val(), ",")).each(function () {
data.push({
id: this,
text: this
});
});
callback(data);
}
});
Some console output for the request (some of the faster examples):
15:00:51 INFO: Processing by KeywordTagsController#find_keywords as JSON
15:00:51 INFO: Parameters: {"q"=>"", "_"=>"1436986845195", "locale_str"=>"fr"}
15:00:54 INFO: Completed 200 OK in 2870ms (Views: 40.6ms | ActiveRecord: 5.2ms)
15:33:45 INFO: Started GET "/keywords/fr?q=mer&_=1436986845196" for 127.0.0.1 at 2015-07-15 15:33:45 -0400
15:33:48 INFO: Processing by KeywordTagsController#find_keywords as JSON
15:33:48 INFO: Parameters: {"q"=>"mer", "_"=>"1436986845196", "locale_str"=>"fr"}
15:33:50 INFO: Completed 200 OK in 2136ms (Views: 5.4ms | ActiveRecord: 113.4ms)
15:33:58 INFO: Started GET "/keywords/fr?q=&_=1436986845197" for 127.0.0.1 at 2015-07-15 15:33:58 -0400
15:33:58 INFO: Processing by KeywordTagsController#find_keywords as JSON
15:33:58 INFO: Parameters: {"q"=>"", "_"=>"1436986845197", "locale_str"=>"fr"}
15:34:00 INFO: Completed 200 OK in 1885ms (Views: 38.7ms | ActiveRecord: 4.6ms)
It turns out that fetching the query results was only slow because I was in the dev environment. In production, it works at the speed one would expect. I'm posting this answer in case others have the same question!

Putting data from a database into highcharts using $.getJSON

I'm having some problems with $.getJSON, I really need some help because I don't know how to solve the problem and I've been stuck here for days. This is the js file that should generate highcharts when selecting a select option in HTML:
$(document).ready(function() {
$("#paese").change(function(){
var seriesOptions = [];
$.getJSON("prova.php", function(data) {
seriesOptions = data;
});
var chart1 = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
spacingLeft: 20,
borderWidth: 1
},
....
series: [{
name: 'Italia',
data: seriesOptions
}],
Is there anything wrong in the first part? When I select an option, it seems like highcharts don't get the php file, but I'm pretty sure it's correct, here it is(PHP file):
<?PHP
header("Content-Type: application/json; charset=UTF-8");
$conn = mysql_connect("localhost", "root");
$paese = null;
if(isset($_GET['paese'])) $paese = $_GET['paese'];
$ok = mysql_select_db("liberta", $conn);
$response = array();
$sql="SELECT `valori`.Punteggio FROM `valori` INNER JOIN `nazioni` ON `valori`.Nazione
= `nazioni`.ID WHERE `nazioni`.Nome = '$paese'";
$res=mysql_query($sql);
while($record=mysql_fetch_row($res)){
$response[] = intval("$record[0]");
}
mysql_close($conn);
print(json_encode($response));
I'm trying to get the data from a database I created with PHPmyadmin and put them directly into highcharts, but it doesn't work. I'd be very pleased if you could help me, also because this is is an exam I have to sit. Thank you very much.
I advice to familair with article about preprocessing data http://docs.highcharts.com/#preprocessing.
You need to have strucuture like:
{
data:[1,2,3]
}
Try to replace
while($record=mysql_fetch_row($res)){
$response[] = intval("$record[0]");
}
with
while($record=mysql_fetch_row($res)){
$response['data'][] = intval($record[0]);
}
Your problem is with the javascript part. When you call $.getJSON, the callback you provide will be called asynchronously when the server responds. Howether in your code you are calling the Highcharts() constructor immediately in a synchronous way. At the point its called the seriesOption variable still equals to []. Try calling the constructor from the callback like this:
$.getJSON("prova.php", function(data) {
var chart1 = new Highcharts.Chart(....
series: [{
name: 'Italia',
data: data}])});

How to display twitter search parse?

My first question with Stackoverflow. How do I display/read twitter search parse data in my webpage?
Below is the code I am working with. I can see 15 object in console.log() but I have no idea on how to show this in web page view.
My coding is below:
$
.ajax({
url : "http://search.twitter.com/search.json?q=gaga&callback=?",
dataType : "json",
timeout:1000,
success : function(data)
{
console.log(data.results);
//console.log(data.results);
//$('#twitter').html(data);// parse data here
},
error : function()
{
alert("Failure!");
},
});
See if this helps http://jsfiddle.net/2cxfN/
$.ajax({
url : "http://search.twitter.com/search.json?q=gaga&callback=?",
dataType : "json",
timeout:1000,
success : function(data)
{
console.log(data.results);
//console.log(data.results);
//$('#twitter').html(data);// parse data here
$.each(data.results, function(i,o){
console.log(o);
$('<img/>', {src:o.profile_image_url}).appendTo('body');
$('<div/>').text(o.from_user).appendTo('body');
});
},
error : function()
{
alert("Failure!");
},
});​
Ah, I see you have a div with an id twitter - you would parse that HTML into what you want using the variables in each object that's in data.results, which I've extracted as o, then appendTo('#twitter');

Rally Analytics 2.0 - Error 413: Request Entity Too Large

I have been writing an app which uses the lookback tool to get the total number of points a project had within it on a certain date. The request to pull this information looks as follows:
getPointsOn: function(date, iOIDs, callback) {
var params = {};
params.find = '{ Iteration: {$in: [' + iOIDs + ']}, PlanEstimate: { $gt: 0 }, __At: "' + date.toISOString() + '" }';
params.fields = '[ "PlanEstimate", "Project" ]';
Ext.Ajax.cors = true;
Ext.Ajax.request({
url: App.qURL,
method: 'GET',
params: params,
withCredentials: true,
success: function(response) {
var points = {};
Ext.Array.each(Ext.JSON.decode(response.responseText).Results, function(US) {
if (points[US.Project] == undefined) points[US.Project] = 0;
points[US.Project] += US.PlanEstimate;
});
callback(points);
},
failure: function() {
console.log('Ajax Failed');
callback({});
}
});
}
It returns an object with Project/Points pairs and works perfectly when 1-2 iteration ObjectIDs are passed to it. The problem is when I start requesting larger data sets. I have been getting the "Request Entity Too Large" error. I assume this is a problem with the request itself although I'm not sure how it could be "too large". What is the likely cause of this error?
Thanks!
You can do an Ext.util.Cookies.clear(cookieName) to remove a cookie. Generally the maximum request size for ALM is 8k so a large pref cookie combined with a large number of iteration oids could hit that limit.
Also, there is a more fully supported way to access the Lookback API in SDK 2.0p4.
http://developer.rallydev.com/apps/2.0p4/doc/#!/api/Rally.data.lookback.SnapshotStore
Ext.create('Rally.data.lookback.SnapshotStore', {
listeners: {
load: function(store, data, success) {
//process data
}
},
fetch: ['PlanEstimate', 'Project'],
filters: [
{
property: 'Iteration',
operator: 'in',
value: iOIDS //an array
},
{
property: 'PlanEstimate',
operator: '>',
value: 0
},
{
property: '__At',
value: date.toISOString()
},
],
autoLoad: true
});
Large state elements, such as the values selected from a picker, should be stored with a Ext.state.LocalStorageProvider instance, rather than a Ext.state.CookieProvider. Assuming that the cookie does not need to be sent to fulfill the query request.

Resources