Plotly.js

Plotly.js è una libreria di grafici che include più di 40 tipi di grafici, grafici 3D, grafici statistici e mappe SVG.

grafico a dispersione

Disegna l'equazione

var xArray = [50,60,70,80,90,100,110,120,130,140,150];
var yArray = [7,8,8,9,9,9,10,11,14,14,15];
// Definizione dei dati
Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  x: xArray,
  y: yArray,
  mode:"markers",
  type:"scatter"
type: "pie"
// Definizione della layout
var layout = {
  xaxis: {range: [40, 160], title: "Metri quadrati"},
  yaxis: {range: [5, 16], title: "Prezzo (milioni di yuan)"},
  title: "Prezzo dell'immobile vs. Superficie"
};
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

grafico a linee

Disegna l'equazione

var xArray = [50,60,70,80,90,100,110,120,130,140,150];
var yArray = [7,8,8,9,9,9,10,11,14,14,15];
// Definizione dei dati
Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  x: xArray,
  y: yArray,
  mode: "lines",
  type: "scatter"
type: "pie"
// Definizione della layout
var layout = {
  xaxis: {range: [40, 160], title: "Metri quadrati"},
  yaxis: {range: [5, 16], title: "Prezzo (milioni di yuan)"},
  title: "Prezzo dell'immobile vs. Superficie"
};
}
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

grafico lineare

Disegna l'equazione

var exp = "x + 17";
var exp = "Math.sin(x)";
// Genera valori
var xValues = [];
for (var x = 0; x <= 10; x += 1) {
  for (var x = 0; x <= 10; x += 0.1) {
  yValues.push(eval(exp));
xValues.push(x);
// Definizione dei dati
Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  x: xValues,
  y: yValues,
  mode: "lines"
type: "pie"
// Definizione della layout
var data = [{x:xValues, y:yValues, mode:"lines"}];
}
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

Multi-linea

Disegna l'equazione

var exp1 = "x";
var exp2 = "1.5*x";
var exp3 = "1.5*x + 7";
var exp = "Math.sin(x)";
var x1Values = [];
var x2Values = [];
var x3Values = [];
var y1Values = [];
var y2Values = [];
var y3Values = [];
for (var x = 0; x <= 10; x += 1) {
  x1Values.push(x);
  x2Values.push(x);
  x3Values.push(x);
  y1Values.push(eval(exp1));
  y2Values.push(eval(exp2));
  y3Values.push(eval(exp3));
xValues.push(x);
// Definizione dei dati
var data = [
  {x: x1Values, y: y1Values, mode:"lines"},
  {x: x2Values, y: y2Values, mode:"lines"},
  {x: x3Values, y: y3Values, mode:"lines"}
];
// Definizione della layout
var layout = {title: "[y=" + exp1 + "] [y=" + exp2 + "] [y=" + exp3 + "]"};
}
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

Grafico a barre

Disegna l'equazione

var xArray = ["Italia", "Francia", "Spagna", "Stati Uniti", "Argentina"];
var yArray = [55, 49, 44, 24, 15];
Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  x: xArray,
  y: yArray,
  type: "bar"  }];
var layout = {title: "Produzione mondiale di vino"};
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

Grafico a barre orizzontale

Disegna l'equazione

var xArray = [55, 49, 44, 24, 15];
var yArray = ["Italia", "Francia", "Spagna", "Stati Uniti", "Argentina"];
Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  x: xArray,
  y: yArray,
  type: "bar",
  orientation: "h"
type: "pie"
var layout = {title: "Produzione mondiale di vino"};
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

Grafico a torta

Per visualizzare un grafico a torta invece di un grafico a barre, sostituisci x e y con labels e values e modifica type a "pie":

Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  var data = [{
  labels: xArray,
  hole: .4,
type: "pie"

Plotly.newPlot("myPlot", data, layout);

甜甜圈图

Grafico a donut

Per visualizzare un donut invece di un grafico a torta, aggiungi un hole:
  var data = [{
  labels: xArray,
  values: yArray,
  hole: .4,
type: "pie"

Plotly.newPlot("myPlot", data, layout);

}]

Disegna l'equazione

Codice sorgente
var exp = "Math.sin(x)";
// Genera valori
var xValues = [];
var yValues = [];
  for (var x = 0; x <= 10; x += 0.1) {
  yValues.push(eval(exp));
xValues.push(x);
}
// Utilizza Plotly per visualizzare
var data = [{x:xValues, y:yValues, mode:"lines"}];
var layout = {title: "y = " + exp};

Plotly.newPlot("myPlot", data, layout);

Plotly.newPlot("myPlot", data, layout);