本文整理汇总了TypeScript中plotly.js.newPlot方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.newPlot方法的具体用法?TypeScript js.newPlot怎么用?TypeScript js.newPlot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.js
的用法示例。
在下文中一共展示了js.newPlot方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
(() => {
const trace1 = {
x: [1999, 2000, 2001, 2002],
y: [10, 15, 13, 17],
type: 'scatter'
} as ScatterData;
const trace2 = {
x: [1999, 2000, 2001, 2002],
y: [16, 5, 11, 9],
type: 'scatter'
} as ScatterData;
const data = [trace1, trace2];
const layout = {
title: 'Sales Growth',
xaxis: {
title: 'Year',
showgrid: false,
zeroline: false
},
yaxis: {
title: 'Percent',
showline: false
}
};
Plotly.newPlot(graphDiv, data, layout);
})();
示例2:
(() => {
// deprecated: calling plot again will add new trace(s) to the plot,
// but will ignore new layout.
const data2 = [{
x: [1999, 2000, 2001, 2002],
y: [10, 9, 8, 7],
type: 'scatter'
} as PlotData];
const layout2 = { title: 'Revenue' };
Plotly.newPlot(graphDiv, data2, layout2);
})();
示例3:
/// <reference path="plotly.js.d.ts" />
import * as Plotly from 'plotly.js';
var data = [
{
x: ['giraffes', 'orangutans', 'monkeys'],
y: [20, 14, 23],
type: 'bar'
}
];
Plotly.newPlot('test', data);
示例4: newPlot
(async () => {
const myPlot = await newPlot(graphDiv, [{
x: [1999, 2000, 2001, 2002],
y: [10, 9, 8, 7],
type: 'scatter'
}]);
myPlot.on('plotly_click', (data) => {
let pn = 0;
let tn = 0;
let colors = [] as string[];
for (const pt of data.points) {
pn = pt.pointNumber;
tn = pt.curveNumber;
colors = pt.data.marker.color as string[];
}
colors[pn] = '#C54C82';
const update = { marker: { color: colors, size: 16 } };
Plotly.restyle('myDiv', update, [tn]);
});
myPlot.on('plotly_hover', (data) => {
let pn = 0;
let tn = 0;
let colors = [] as string[];
for (const pt of data.points) {
pn = pt.pointNumber;
tn = pt.curveNumber;
colors = pt.data.marker.color as string[];
}
colors[pn] = '#C54C82';
const update = { marker: { color: colors, size: 16 } };
Plotly.restyle('myDiv', update, [tn]);
});
myPlot.on('plotly_unhover', (data) => {
let pn = 0;
let tn = 0;
let colors = [] as string[];
for (const pt of data.points) {
pn = pt.pointNumber;
tn = pt.curveNumber;
colors = pt.data.marker.color as string[];
}
colors[pn] = '#00000';
const update = { marker: { color: colors, size: 16 } };
Plotly.restyle('myDiv', update, [tn]);
});
myPlot.on('plotly_selected', (data) => {
const x = [] as Datum[];
const y = [] as Datum[];
const N = 1000;
const color1 = '#7b3294';
const color1Light = '#c2a5cf';
const colors = [] as string[];
for (let i = 0; i < N; i++) colors.push(color1Light);
data.points.forEach((pt) => {
x.push(pt.x);
y.push(pt.y);
colors[pt.pointNumber] = color1;
});
Plotly.restyle(myPlot, {
x: [x, y]
}, [1, 2]);
Plotly.restyle(myPlot, {
'marker.color': [colors]
}, [0]);
});
myPlot.on('plotly_restyle', (data) => {
console.log('restyling');
});
myPlot.on('plotly_doubleclick', () => {
const orgColors = ['#00000', '#00000', '#00000',
'#00000', '#00000', '#00000'];
const update = { marker: { color: orgColors, size: 16 } };
Plotly.restyle('myDiv', update);
});
myPlot.on('plotly_beforeplot', (event) => {
console.log('plotting');
const okToPlot = true;
return okToPlot;
});
myPlot.on('plotly_afterplot', () => {
console.log('done plotting');
});
myPlot.on('plotly_animatingframe', (event) => {
console.log(`animating ${event.frame.name} with ${event.animation.transition.easing}`);
});
//.........这里部分代码省略.........
示例5: unpack
//.........这里部分代码省略.........
},
{
country: "Austria",
year: 2001,
pop: 7914969,
continent: "Europe",
lifeExp: 76.04,
gdpPercap: 27042.01868
},
];
interface DataRow {
[key: string]: string | number;
}
function unpack(rows: DataRow[], key: string) {
return rows.map((row: DataRow) => row[key]);
}
const trace1 = {
mode: 'markers',
x: unpack(testrows, 'lifeExp'),
y: unpack(testrows, 'gdpPercap'),
text: unpack(testrows, 'continent'),
marker: {
size: unpack(testrows, 'pop'),
sizemode: "area",
sizeref: 200000
},
type: 'scatter',
transforms: [
{
type: 'filter',
target: unpack(testrows, 'year'),
operation: '=',
value: '2002'
}, {
type: 'groupby',
nameformat: `%{group}`,
groups: unpack(testrows, 'continent'),
styles: [
{ target: 'Asia', value: { marker: { color: 'red' } } },
{ target: 'Europe', value: { marker: { color: 'blue' } } },
{ target: 'Americas', value: { marker: { color: 'orange' } } },
{ target: 'Africa', value: { marker: { color: 'green' } } },
{ target: 'Oceania', value: { marker: { color: 'purple' } } }
]
}, {
type: 'aggregate',
groups: unpack(testrows, 'continent'),
aggregations: [
{ target: 'x', func: 'avg' },
{ target: 'y', func: 'avg' },
{ target: 'marker.size', func: 'sum' }
]
}]
} as PlotData;
const trace2 = {
yaxis: 'y2',
x: unpack(testrows, 'lifeExp'),
name: 'x density',
marker: { color: 'rgb(102,0,0)' },
type: 'histogram'
} as PlotData;
const trace3 = {
xaxis: 'x2',
y: unpack(testrows, 'gdpPercap'),
name: 'y density',
marker: { color: 'rgb(102,0,0)' },
type: 'histogram'
} as PlotData;
const data = [trace1, trace2, trace3];
const layout = {
title: 'Gapminder',
xaxis: {
title: 'Life Expectancy',
domain: [0, 0.85],
showgrid: false,
zeroline: false
},
yaxis: {
title: 'GDP per Cap',
showline: false,
domain: [0, 0.85],
showgrid: false,
zeroline: false
},
xaxis2: {
domain: [0.85, 1],
showgrid: false,
zeroline: false
},
yaxis2: {
domain: [0.85, 1],
showgrid: false,
zeroline: false
}
};
Plotly.newPlot(graphDiv, data, layout);
})();
示例6: newPlot
(async () => {
const myPlot = await newPlot(graphDiv, [{
x: [1999, 2000, 2001, 2002],
y: [10, 9, 8, 7],
type: 'scatter'
}]);
myPlot.on('plotly_click', (data) => {
let pn = 0;
let tn = 0;
let colors = [] as string[];
for (const pt of data.points) {
pn = pt.pointNumber;
tn = pt.curveNumber;
colors = pt.data.marker.color as string[];
}
colors[pn] = '#C54C82';
const update = { marker: { color: colors, size: 16 } };
Plotly.restyle('myDiv', update, [tn]);
});
myPlot.on('plotly_hover', (data) => {
let pn = 0;
let tn = 0;
let colors = [] as string[];
for (const pt of data.points) {
pn = pt.pointNumber;
tn = pt.curveNumber;
colors = pt.data.marker.color as string[];
}
colors[pn] = '#C54C82';
const update = { marker: { color: colors, size: 16 } };
Plotly.restyle('myDiv', update, [tn]);
});
myPlot.on('plotly_unhover', (data) => {
let pn = 0;
let tn = 0;
let colors = [] as string[];
for (const pt of data.points) {
pn = pt.pointNumber;
tn = pt.curveNumber;
colors = pt.data.marker.color as string[];
}
colors[pn] = '#00000';
const update = { marker: { color: colors, size: 16 } };
Plotly.restyle('myDiv', update, [tn]);
});
myPlot.on('plotly_selected', (data) => {
const x = [] as number[];
const y = [] as number[];
const N = 1000;
const color1 = '#7b3294';
const color1Light = '#c2a5cf';
const colors = [] as string[];
for (let i = 0; i < N; i++) colors.push(color1Light);
data.points.forEach((pt) => {
x.push(pt.x);
y.push(pt.y);
colors[pt.pointNumber] = color1;
});
Plotly.restyle(myPlot, {
x: [x, y]
}, [1, 2]);
Plotly.restyle(myPlot, {
'marker.color': [colors]
}, [0]);
});
myPlot.on('plotly_restyle', (data) => {
console.log('restyling');
});
myPlot.on('plotly_doubleclick', () => {
const orgColors = ['#00000', '#00000', '#00000',
'#00000', '#00000', '#00000'];
const update = { marker: { color: orgColors, size: 16 } };
Plotly.restyle('myDiv', update);
});
myPlot.on('plotly_afterplot', () => {
console.log('done plotting');
});
})();