HighCharts + Consulta a um banco de dados

1 resposta
V

Ola,
Apos instalaçao do HighCharts ([url]http://geekvigarista.com/app/navegadores/graficos-em-aplicacoes-web-usando-highcharts-js-1[/url]) Fiz um HTML para me mostrar um grafico com relaçao aos valores que eu informar:

<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>GRAPHS</title>

		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
		<script type="text/javascript">
$(function () {
        $('#container').highcharts({
            chart: {
                type: 'spline'
            },
            title: {
                text: 'NUMERO DE USERS DO PORTAL por ano'
            },
            subtitle: {
                text: 'Source: WorldClimate.com'
            },
            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            },
            yAxis: {
                title: {
                    text: 'Users'
                },
                labels: {
                    formatter: function() {
                        return this.value
                    }
                }
            },
            tooltip: {
                crosshairs: true,
                shared: true
            },
            plotOptions: {
                spline: {
                    marker: {
                        radius: 4,
                        lineColor: '#666666',
                        lineWidth: 1
                    }
                }
            },
            series: [{
                name: '2012',
                marker: {
                    symbol: 'square'
                },
                data: [0, 0, 0, 0, 0, 0, 1, {
                    y: 2,
                    marker: {
                        //symbol: 'url(http://www.highcharts.com/demo/gfx/sun.png)'
                    }
                }, 2, 1, 4, 5]
    
            }, {
                name: '2013',
                marker: {
                    //symbol: 'diamond'
                },
                data: [{
                    y: 1,
                    marker: {
                        //symbol: 'url(http://www.highcharts.com/demo/gfx/snow.png)'
                    }
                }, 1, 1, 1, 0, 0, 0, 0, 2, 1, 0, 0]
            }]
        });
    });
    

		</script>
	</head>
	<body>
<script src="../js/highcharts.js"></script>
<script src="../js/modules/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

	</body>
</html>

AGORA gostaria de mostrar os valores de um banco de dados nao LOCALHOST mysql.
Alguém me ajuda?

Obrigada,

1 Resposta

C

Ola. Não sei se já resolveu esse problema, mas a forma que eu encontrei foi criar uma pagina xml, que recupera os dados do banco, e receber esses dados na pagina onde fica o script highcharts.

pagina xml obs: fiz a pagina em asp e coloquei o nome da pagina com grafico_xml.asp

<%
response.ContentType = "text/xml"
response.charset = “ISO-8859-1”
%>

<%

tx_saida = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbcrlf &_
"<target>" & vbcrlf

set indice = con.execute("SELECT nr_valor FROM ibp_indice WHERE dt_dataehora BETWEEN '2013/10/17 00:30:00' and '2013/10/17 00:59:00' ORDER BY dt_dataehora")

do while not indice.EOF
	'tx_saida = tx_saida & "<target>" & vbcrlf
		'tx_saida = tx_saida & "<data>" & vbcrlf
			tx_saida = tx_saida & "<nr_valor>" & replace(indice("nr_valor"),",",".") & "</nr_valor>" & vbcrlf
		'tx_saida = tx_saida & "</data>" & vbcrlf
	'tx_saida = tx_saida & "</target>" & vbcrlf
	indice.MoveNext 
loop

tx_saida = tx_saida & "</target>"

response.write(tx_saida)

%>

agora como ira ficar o script Highcharts

$(document).ready(function()
			{
				var options = 
				{
					chart: 
					{
						renderTo: 'grafico1'						
					},
				
					xAxis: 
					{
						type: 'datetime',
						
						 labels: 
						{
							enabled: false
						}
					},
					
					title: 
					{
						text: null
					},
											
					yAxis: 
					{
						min: 0,
						title: 
						{
							text: null
						},
						
						 labels: 
						{
							enabled: true
						}
					},
					
					legend: 
					{
						enabled: false
					},
					
					exporting: 
					{
						enabled: false
					},
					plotOptions: 
					{
						series: 
						{
							pointStart: Date.UTC(ano, mes, dia, hora, minuto2), // ano - mes - dia - hora - minuto
							pointInterval: 1 * 60 * 1000, //intervalo de 1 minuto
						}
					},
series: []														
				}					
					
			   // Load the data from the XML file 
				$.get('grafico/grafico_xml.asp', function(xml) 
				{
					// Split the lines
					var $xml = $(xml);
					
					// push series
					$xml.find('target').each(function(i, series) 
					{
						var seriesOptions = 
						{
							//name: $(series).find('name').text(),
							data: []
						};
						
						// push data points
						$(series).find('nr_valor').each(function(i, point) 
						{
								seriesOptions.data.push
								(
										parseInt($(point).text())
								);
						});
							
						// add it to the options
						options.series.push(seriesOptions);
					});
					var chart = new Highcharts.Chart(options);	
				});

espero ter ajudado, abs.

Criado 30 de abril de 2013
Ultima resposta 3 de nov. de 2013
Respostas 1
Participantes 2