Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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
Comments
[no name] 7-Sep-12 6:49am    
googling will help!!!!!
hh_7 7-Sep-12 6:53am    
;) really ?
ZurdoDev 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.
hh_7 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
ZurdoDev 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

C#
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...
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900