Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rGraph problem
//On ready, load graphs
$(function() {
loadGraphIndicadoresDeArtefacto();
});
//Load graphs for Indicadores of an artefacto
var loadGraphIndicadoresDeArtefacto = function(){
if($('#GraphContainer_Indicadores').length == 0)return;
//Obtain the indicadores related to this artefacto from API
$.getJSON('http://' + window.location.host + '/api/getIndicadores/mandoCode='+$('#mandoCode').val()+'&intangibleCode='+$('#intangibleCode').val()+'&artefactoCode='+$('#artefactoCode').val(), function(response) {
if(response.result == "200"){
//Create the numer of graph containers based on the number of indicadores
var graphContainers="";
$(response.indicadores).each(function(index)
{
graphContainers = '<canvas id="graphIndicadorIndex_'+index+'" width="460" height="260">[No canvas support]</canvas>';
$('#GraphContainer_Indicadores').append(graphContainers);
//Prepare the data
var arrValorReal = [];
var arrValorMeta = [];
var arrFiscalYear = [];
var arrTooltipsReal = [];
var arrTooltipsMeta = [];
var nombreIndicador="";
var valoresNegativos = false;
$(response.indicadores[index]).each(function(index2){
arrValorReal.push(response.indicadores[index][index2].valorReal);
arrValorMeta.push(response.indicadores[index][index2].valorMeta);
arrFiscalYear.push(response.indicadores[index][index2].fiscalYear);
nombreIndicador = response.indicadores[index][index2].nombreIndicador;
arrTooltipsReal.push(String(Math.round(response.indicadores[index][index2].valorReal*100)/100));
arrTooltipsMeta.push(String(Math.round(response.indicadores[index][index2].valorMeta*100)/100));
//Check if we have negative values so we can show them
if(response.indicadores[index][index2].valorReal < 0 || response.indicadores[index][index2].valorMeta < 0){
valoresNegativos = true;
}
});
var graphIndicador = new RGraph.Line('graphIndicadorIndex_'+index, arrValorReal,arrValorMeta);
graphIndicador.Set('chart.colors',['#969696','#1994A4']);
graphIndicador.Set('chart.labels', arrFiscalYear);
graphIndicador.Set('chart.key', ["Valor Real","Meta"]);
graphIndicador.Set('chart.key.position.x',270);
graphIndicador.Set('chart.key.position.y',30);
graphIndicador.Set('chart.key.position', 'gutter');
graphIndicador.Set('chart.key.position.gutter.boxed', false);
graphIndicador.Set('chart.tickmarks', 'circle');
graphIndicador.Set('chart.shadow', true);
graphIndicador.Set('chart.shadow.offsetx', 1);
graphIndicador.Set('chart.shadow.offsety', 1);
graphIndicador.Set('chart.shadow.blur', 3);
graphIndicador.Set('chart.hmargin', 15);
graphIndicador.Set('chart.gutter.bottom', 45);
graphIndicador.Set('chart.background.grid.vlines', false);
graphIndicador.Set('chart.linewidth', 3);
graphIndicador.Set('chart.tooltips', ['1','1','1','1','1','1','1','1','1','1','1','1']); //<- THE PROBLEM IS HERE
graphIndicador.Set('chart.tooltips.highlight', false);
if(valoresNegativos === true) graphIndicador.Set('chart.xaxispos', 'center');
$('#graphIndicadorIndex_'+index).before('<h4>'+nombreIndicador+'</h4>');
RGraph.isOld() ? graphIndicador.Draw() : RGraph.Effects.Line.jQuery.Trace(graphIndicador);
});
}
else{
//something went wrong
}
});
//Load each graph content
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.