Click here to Skip to main content
11,417,240 members (51,135 online)
Rate this: bad
good
Please Sign up or sign in to vote.
In visual studio i have a solution wich contains a webpage that I have two function on that but one is:

function isThatAColor(s) {
...
}


and the other is:

$(function () {
...
}


Inside the function of jquery i need to use some variables that i have in javascript function.

Anyone knows how ?
Posted 7-Sep-12 1:46am
hh_7643
Comments
Karthik_J, Coimbatore at 7-Sep-12 6:49am
   
googling will help!!!!!
Hugo Henrique at 7-Sep-12 6:53am
   
;) really ?
ryanb31 at 7-Sep-12 8:09am
   
Just declare your variables outside of your functions and they will be global. jQuery is JavaScript so they can share.
Hugo Henrique at 7-Sep-12 8:44am
   
I have already tried but doesn´t work, well javascript function works but then the jquery function doesn´t work ... wich is the more important because is where i am drawing a graph
ryanb31 at 7-Sep-12 8:50am
   
Explain what you mean by doesn't work. Your jQuery function is unnamed and will run as the page loads so it may be you don't have your global variables set yet.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

var color = new RGBColor(s);
var max = Math.max(color.r, color.g);
max = Math.max(max, color.b);
var scale = 1.0 / max;
 
function isThatAColor(s) {
 
    if (color.ok) {
        document.getElementById('result').style.backgroundColor = 'rgb(' + color.r + ', ' + color.g + ', ' + color.b + ')';
        document.getElementById('result-text').innerHTML = 'Red: ' + color.r + ', Green: ' + color.g + ', Blue: ' + color.b
              + '<br />' + color.toRGB() + ', Hex: ' + color.toHex();
        alert("Vermelho: " + color.r + "\n" + "Verde: " + color.g + "\n" + "Azul: " + color.b);
    }
    else {
        document.getElementById('result-text').innerHTML = 'Essa cor não existe na livraria, se pretender adicionar uma nova cor visite a livraria "RGB.js".';
        document.getElementById('result').style.backgroundColor = 'rgb(255, 255, 255)';
    }
};
 
$(function () {
 
    var perShapeGradient = {
        x1: 0.3,
        y1: 0,
        x2: 0,
        y2: 0
    };
 
    var chart;
    $(document).ready(function () {
 
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column',
                backgroundColor: "#E0E0E0",
                borderRadius: 0
            },
            title: {
                text: ''  //Título principal
            },
            xAxis: {
                gridLineWidth: 0,
                categories: ['JULY 31, 2010', 'JULY 31, 2011', 'JULY 31, 2012']
            },
            yAxis: {
                gridLineWidth: 0.2,
                gridLineColor: '#000',
                tickInterval: 100,
                min: 0,
                max: 400,
                title: {
                    text: '' //Título vertical
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                    }
                }
            },
            legend: {
                align: 'center',
                x: 0,
                verticalAlign: 'bottom',
                y: 13,
                floating: true,
                borderColor: '#CCC',
                borderWidth: 0,
                shadow: false
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.x + '</b><br/>' +
                        this.series.name + ': ' + this.y + '<br/>' +
                        'Total: ' + this.point.stackTotal;
                }
            },
            plotOptions: {
                series: {
                    animation: {
                        duration: 1500              //Controlar tempo animação
                    }
                },
                column: {
                    borderWidth: 1,
                    borderColor: '#000',
                    stacking: 'normal',
                    dataLabels: { enabled: true, color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white' }
                }
            },
            series: [{
                name: 'LONG TERM',
                data: [0, 131, 145],
                borderRadius: [5, 5, 5, 5]
            }, {
                name: 'MEDIUM TERM',
                data: [0, 48, 54]
            }, {
                name: 'SHORT TERM',
                data: [0, 84, 99]
            }],
            colors: [
            {
                linearGradient: perShapeGradient,
                stops: [
                    [0, 'rgb(107, 66, 38)'],
                    [0.15, 'rgb(232,232,232)'],
                    [0.30, 'rgb(232,232,232)'],
                    [0.8, 'rgb(97,97,97)'],
                    [1, 'rgb(131,139,0)']
 
                    //[0.15, (scale*color.r, scale*color.g, scale*color.b)],
                    //[0.30, (0.7*color.r, 0.7*color.g, 0.7*color.b)],
                    //[0.8, (0.95*color.r, 0.95*color.g, 0.95*color.b)],
                    //[1, (0.8*color.r, 0.8*color.g, 0.8*color.b)]
                ]
            },
            {
                linearGradient: perShapeGradient,
                stops: [
                    [0, 'rgb(97, 97, 97)'],
                    [0.15, 'rgb(232,232,232)'],
                    [0.30, 'rgb(232,232,232)'],
                    [0.8, 'rgb(97,97,97)'],
                    [1, 'rgb(131,139,0)']
 
                    //[0.15, (scale*color.r, scale*color.g, scale.color.b)],
                    //[0.30, (0.7*color.r, 0.7*color.g, 0.7*color.b)],
                    //[0.8, (0.95*color.r, 0.95*color.g, 0.95*color.b)],
                    //[1, (0.8*color.r, 0.95*color.g, 0.95*color.b)]
                ]
            },
            {
                linearGradient: perShapeGradient,
                stops: [
                    [0, 'rgb(92,64,51)'],
                    [0.15, 'rgb(232,232,232)'],
                    [0.30, 'rgb(232,232,232)'],
                    [0.8, 'rgb(131,139,0)'],
                    [1, 'rgb(131,139,0)']
 
                    //[0.15, (scale*color.r, scale*color.g, scale.color.b)],
                    //[0.30, (0.7*color.r, 0.7*color.g, 0.7*color.b)],
                    //[0.8, (0.95*color.r, 0.95*color.g, 0.95*color.b)],
                    //[1, (0.8*color.r, 0.95*color.g, 0.95*color.b)]
                ]
            }, ]
        });
    });
});


there...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sascha Lefévre 340
1 Abhinav S 248
2 Sergey Alexandrovich Kryukov 245
3 OriginalGriff 235
4 Richard Deeming 160
0 Sergey Alexandrovich Kryukov 9,295
1 OriginalGriff 7,592
2 Maciej Los 3,718
3 Abhinav S 3,456
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web01 | 2.8.150427.4 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100