【发布时间】:2015-08-11 07:47:47
【问题描述】:
我正在使用 Greg Ross 创建的 JavaScript 中的 3D 曲面图。除了我无法控制轴刻度标签、限制和轴刻度位置之外,一切都运行良好。我的最终目标是在 x 和 y 轴上使用对数刻度,为此我需要控制刻度标签与 x 和 y 轴原点之间的距离。
但就我而言,我只能选择轴标签:
// WeKno
var canvas_height = ComputedStyleValue('surfacePlotDiv', 'height');
var canvas_width = ComputedStyleValue('surfacePlotDiv', 'width');
var surfacePlot;
var data, data2, options, basicPlotOptions, glOptions, animated, plot1, plot2, values, values2;
var numRows = 19;
var numCols = 20;
var tooltipStrings = new Array();
var tooltipStrings2 = new Array();
function setUp(){
values = new Array();
data = {
nRows: numRows,
nCols: numCols,
formattedValues: values
};
surfacePlot = new SurfacePlot(document.getElementById("surfacePlotDiv"));
// Don't fill polygons in IE < v9. It's too slow.
var fillPly = true;
// Define a colour gradient.
var colour1 = {
red: 0,
green: 0,
blue: 255
};
var colour2 = {
red: 0,
green: 255,
blue: 255
};
var colour3 = {
red: 0,
green: 255,
blue: 0
};
var colour4 = {
red: 255,
green: 255,
blue: 0
};
var colour5 = {
red: 255,
green: 0,
blue: 0
};
var colours = [colour1, colour2, colour3, colour4, colour5];
// Axis labels.
var xAxisHeader = "F";
var yAxisHeader = "C";
var zAxisHeader = "Cost [$]";
var renderDataPoints = false;
var background = '#ffffff';
var axisForeColour = '#000000';
var hideFloorPolygons = true;
var chartOrigin = {
x: 0,
y: 0
};
// Options for the basic canvas plot.
basicPlotOptions = {
fillPolygons: fillPly,
tooltips: tooltipStrings,
renderPoints: renderDataPoints
}
// Options for the webGL plot.
var xLabels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var yLabels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
//var zLabels = [0, 1, 2, 3, 4, 5];
// These labels are used when autoCalcZScale is false;
glOptions = {
xLabels: xLabels,
yLabels: yLabels,
chkControlId: "allowWebGL",
autoCalcZScale: true,
animate: true
};
// Options common to both types of plot.
options = {
xPos: 0,
yPos: 0,
width: canvas_width,
height: canvas_height,
colourGradient: colours,
xTitle: xAxisHeader,
yTitle: yAxisHeader,
zTitle: zAxisHeader,
backColour: background,
axisTextColour: axisForeColour,
hideFlatMinPolygons: hideFloorPolygons,
origin: chartOrigin
};
newplot();
coordinateCharts();
}
function coordinateCharts(){
// Link the two charts for rotation.
plot1 = surfacePlot.getChart();
if (!plot1 || !plot2)
return;
plot1.otherPlots = [plot2];
plot2.otherPlots = [plot1];
}
setUp();
function toggleChart(chkbox){
surfacePlot.draw(data, options, basicPlotOptions, glOptions);
surfacePlot2.draw(data2, options, basicPlotOptions2, glOptions2);
coordinateCharts();
}
// ================== parser, evaluator ========================== WeKno
function Demoparse(valueArray, toolTips){
var idx = 0;
var dataCF = generateDataCF();
//var max = maxValue(dataCF);
for (var x = 0; x < 19; x++) {
valueArray[x] = new Array();
for (var y = 0; y < 20; y++) {
var temp = dataCF[x][y];
valueArray[x][y] = temp;
toolTips[idx] = "x:" + x + ", y:" + y + " = " + 1;
idx++;
}
}
}
function newplot(){
Demoparse(values, tooltipStrings);
surfacePlot.draw(data, options, basicPlotOptions, glOptions);
coordinateCharts();
}
function ComputedStyleValue(ID, property)// WeKno
{
var e = document.getElementById(ID);
return (window.getComputedStyle(e, null).getPropertyValue(property));
}
有谁知道如何控制 x 和 y 轴刻度标签的位置以构建对数刻度轴? 请帮帮我
【问题讨论】:
标签: javascript plot axis surface