[HTML][CANVAS] Convertir l'échelle d'un canvas pour un graphique

Par Weezy, il y a 9 ans


Les bases HTML/CSS

Bonjour,
J'ai réalisé un graphique que j'ai affiché grâce à un canvas et maintenant je voudrais adapter l'échelle du canvas à l’échelle de mon graphique.

Si quelqu'un sait comment faire pour adapter l'échelle d'un canvas à l’échelle d'un graphique, je lui serait reconnaissant de m'indiquer comment faire.

6 réponses

AlexJM, il y a 9 ans

Je ne comprends point la question

Weezy, il y a 9 ans

Je veux adapter la taille de mon graphique à la taille de mon canvas.

AlexJM, il y a 9 ans

Tu l'affiches comment ton graphique ? Avec un plugin jquery ou à la main ?

Weezy, il y a 9 ans

J'affiche mon graphique avec un canvas.
Voici mon code

<html> <body> <script> window.onload = function (){ RGraph.AJAX.getJSON('getJson.php', drawLine); var type = true; function drawLine (json){ // Now draw the chart var line = new RGraph.Line({ id: 'line', data: [json.a, json.b], options: { annotatable: true, annotateLinewidth: 2, contextmenu: [['Effacer les annotations', function () {RGraph.Clear(line.canvas); RGraph.ClearAnnotations(line.canvas); line.Draw();}]], key: ['a', 'b'], labels: json.nom, title: 'Exemple courbe', gutterTop: 40, gutterBottom:40, gutterLeft: 40, ymax: 8, tickmarks: 'circle', numxticks: 0, } }).trace(); } </script> <canvas id="line" width="650" height="300">[No canvas support]</canvas><br /><br/> </body> </html>
AlexJM, il y a 9 ans

Désolé je ne saurais t'aider je n'ai jamais utilisé RGraph :/
Si jamais tu pouvais changer de plugin, je te conseille http://www.chartjs.org/, il me semble que le graphique prend 100% du canvas par défaut

Weezy, il y a 9 ans

Ok merci quand même :)