有谁知道如何在FLOT中创建对数图表?
基本上我正在尝试创建一个类似于此处所示的图表(左上角):http: //leto.net/plot/examples/logarithms.html
但是,我尝试使用相同的选项,但它没有以相同的方式显示图表.我认为从那以后考虑到这个帖子已经很老了,我一定会对FLOT进行很多改动.
如果有人有任何想法,请告诉我.
谢谢.
Mar*_*ark 18
您可以使用yaxis上的"transform"选项执行此操作.
看到这里的工作.
$(function () {
// setup plot
function sampleFunction(x1, x2, func) {
var d = [ ];
var step = (x2-x1)/300;
for (var i = x1; i < x2; i += step )
d.push([i, func( i ) ]);
return d;
}
var options1 = {
lines: { show: true },
xaxis: { ticks: 4 },
yaxis: { ticks: [0.001,0.01,0.1,1,10,100],
transform: function(v) {return Math.log(v+0.0001); /*move away from zero*/},
tickDecimals: 3 },
grid: { hoverable: true, clickable: true, color: "#999" }
};
var data1 = sampleFunction( 0, 5, function(x){ return Math.exp(x)*Math.sin(x)*Math.sin(x) } );
var plot1 = $.plot($("#chart1"), [ { label: "exp(x)sin(x)^2", data: data1 } ], options1);
});
Run Code Online (Sandbox Code Playgroud)
完整工作代码:
$(function () {
// setup plot
function sampleFunction(x1, x2, func) {
var d = [ ];
var step = (x2-x1)/300;
for (var i = x1; i < x2; i += step )
d.push([i, func( i ) ]);
return d;
}
var options1 = {
lines: { show: true },
xaxis: { ticks: 4 },
yaxis: { ticks: [0.001,0.01,0.1,1,10,100],
transform: function(v) {return Math.log(v+0.0001); /*move away from zero*/} , tickDecimals: 3 },
grid: { hoverable: true, clickable: true , color: "#999"}
};
var data1 = sampleFunction( 0, 5, function(x){ return Math.exp(x)*Math.sin(x)*Math.sin(x) } );
var plot1 = $.plot($("#chart1"), [ { label: "exp(x)sin(x)^2", data: data1} ], options1);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js"></script>
<br/><br/>
<div id="chart1" style="width:600px;height:300px;"></div>Run Code Online (Sandbox Code Playgroud)
小智 5
伟大的工作马克
由于对数图中Y轴的刻度是10的幂,
我想分享Y轴刻度的增强,这里是
$(function () {
// setup plot
function sampleFunction(x1, x2, func) {
var d = [ ];
var step = (x2-x1)/300;
for (var i = x1; i < x2; i += step )
d.push([i, func( i ) ]);
return d;
}
var options1 = {
lines: { show: true },
xaxis: { ticks: 4 },
yaxis: { ticks: [0.001,0.01,0.1,1,10,100],
transform: function(v) {return Math.log(v+0.0001); /*move away from zero*/} , tickDecimals: 3 ,
tickFormatter: function (v, axis) {return "10" + (Math.round( Math.log(v)/Math.LN10)).toString().sup();}
},
grid: { hoverable: true, clickable: true , color: "#999"}
};
var data1 = sampleFunction( 0, 5, function(x){ return Math.exp(x)*Math.sin(x)*Math.sin(x) } );
var plot1 = $.plot($("#chart1"), [ { label: "exp(x)sin(x)" + "2".sup(), data: data1} ], options1);
});
Run Code Online (Sandbox Code Playgroud)
如果有更好的方法,请告诉我.
谢谢.