IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Afficher graphique Javascript


Sujet :

JavaScript

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Etudiant
    Inscrit en
    Juin 2014
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Etudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2014
    Messages : 63
    Points : 33
    Points
    33
    Par défaut Afficher graphique Javascript
    Bonjour,
    J'ai trouvé ce code pour afficher des graphiques : https://jsfiddle.net/f1q4d5th/#&togetherjs=GrbdjgkcCC

    Du coup je me suis fais 3 fichier :
    stats.php :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <script src='graph.js'></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
    <script src='https://ajax.googleapis.com/ajax/libs/prototype/1.7.3.0/prototype.js'></script>
    <link rel='stylesheet' href='./css/style.css' />
     
    <div id="container"></div>
    graph.js :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    /*
    The purpose of this demo is to demonstrate how multiple charts on the same page can be linked
    through DOM and Highcharts events and API methods. It takes a standard Highcharts config with a
    small variation for each data set, and a mouse/touch event handler to bind the charts together.
    */
     
    $(function() {
     
      /**
       * In order to synchronize tooltips and crosshairs, override the
       * built-in events with handlers defined on the parent element.
       */
      $('#container').bind('mousemove touchmove touchstart', function(e) {
        var chart,
          point,
          i,
          event;
     
        for (i = 0; i < Highcharts.charts.length; i = i + 1) {
          chart = Highcharts.charts[i];
          event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
          point = chart.series[0].searchPoint(event, true); // Get the hovered point
     
          if (point) {
            point.highlight(e);
          }
        }
      });
      /**
       * Override the reset function, we don't need to hide the tooltips and crosshairs.
       */
      Highcharts.Pointer.prototype.reset = function() {
        return undefined;
      };
     
      /**
       * Highlight a point by showing tooltip, setting hover state and draw crosshair
       */
      Highcharts.Point.prototype.highlight = function(event) {
        this.onMouseOver(); // Show the hover marker
        this.series.chart.tooltip.refresh(this); // Show the tooltip
        this.series.chart.xAxis[0].drawCrosshair(event, this); // Show the crosshair
      };
     
      /**
       * Synchronize zooming through the setExtremes event handler.
       */
      function syncExtremes(e) {
        var thisChart = this.chart;
     
        if (e.trigger !== 'syncExtremes') { // Prevent feedback loop
          Highcharts.each(Highcharts.charts, function(chart) {
            if (chart !== thisChart) {
              if (chart.xAxis[0].setExtremes) { // It is null while updating
                chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {
                  trigger: 'syncExtremes'
                });
              }
            }
          });
        }
      }
     
      // Get the data. The contents of the data file can be viewed at
      // https://github.com/highcharts/highcharts/blob/master/samples/data/activity.json
      $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=activity.json&callback=?', function(activity) {
        $.each(activity.datasets, function(i, dataset) {
     
          // Add X values
          dataset.data = Highcharts.map(dataset.data, function(val, j) {
            return [activity.xData[j], val];
          });
     
          $('<div class="chart">')
            .appendTo('#container')
            .highcharts({
              chart: {
                marginLeft: 40, // Keep all charts left aligned
                spacingTop: 20,
                spacingBottom: 20
              },
              title: {
                text: dataset.name,
                align: 'left',
                margin: 0,
                x: 30
              },
              credits: {
                enabled: false
              },
              legend: {
                enabled: false
              },
              xAxis: {
                crosshair: true,
                events: {
                  setExtremes: syncExtremes
                },
                labels: {
                  format: '{value} km'
                }
              },
              yAxis: {
                title: {
                  text: null
                }
              },
              tooltip: {
                positioner: function() {
                  return {
                    x: this.chart.chartWidth - this.label.width, // right aligned
                    y: -1 // align to title
                  };
                },
                borderWidth: 0,
                backgroundColor: 'none',
                pointFormat: '{point.y}',
                headerFormat: '',
                shadow: false,
                style: {
                  fontSize: '18px'
                },
                valueDecimals: dataset.valueDecimals
              },
              series: [{
                data: dataset.data,
                name: dataset.name,
                type: dataset.type,
                color: Highcharts.getOptions().colors[i],
                fillOpacity: 0.3,
                tooltip: {
                  valueSuffix: ' ' + dataset.unit
                }
              }]
            });
        });
      });
    });
    et style.css :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    .chart {
      min-width: 320px;
      max-width: 800px;
      height: 220px;
      margin: 0 auto;
    }
    Mais quand j'ouvre stats.php dans mon navigateur, il m'affiche une page blanche.
    Dans la console il y a écrit : graph.js : 7 : Uncaught ReferenceError: $ is not defined

  2. #2
    Rédacteur/Modérateur

    Avatar de SylvainPV
    Profil pro
    Inscrit en
    Novembre 2012
    Messages
    3 375
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2012
    Messages : 3 375
    Points : 9 944
    Points
    9 944
    Par défaut
    Bonjour,

    Déclare graph.js après les bibliothèques dont il a besoin
    One Web to rule them all

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Etudiant
    Inscrit en
    Juin 2014
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Etudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2014
    Messages : 63
    Points : 33
    Points
    33
    Par défaut
    merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 28/11/2006, 07h23
  2. Réponses: 7
    Dernier message: 23/04/2006, 23h07
  3. [XPATH] afficher variable javascript ds xpath
    Par claireenes dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 07/04/2006, 10h39
  4. Javascript-html: ne pas afficher le javascript:void(0)
    Par Anarianthe dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 01/02/2006, 23h32
  5. Afficher un javascript
    Par ghyosmik dans le forum Autres Logiciels
    Réponses: 4
    Dernier message: 21/10/2005, 10h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo