如何控制 flot 中的刻度标签大小
我有一个在 flot 中呈现的基本条形图(5 个条形图,显示每个状态的百分比)。
$.plot($("#placeholder"), [
{
label: 'Failed',
data: [[0,10]],
bars: { show: true }
},
{
label: 'Passed',
data: [[1,15]],
bars: { show: true }
},
{
label: 'Not Run',
data: [[2,30]],
bars: { show: true }
},
{
label: 'Blocked',
data: [[3,5]],
bars: { show: true }
},
{
label: 'In Progress',
data: [[4,40]],
bars: { show: true }
}
],
{
xaxis: {
ticks: [[0.5, "Failed"], [1.5, "Passed"], [2.5, "Not Run"], [3.5, "Blocked"], [4.5, "In Progress"]]
},
legend: {
show: false
}
});
我发现用于 x 轴上刻度值的字体有点太大,尤其是当图形以小尺寸显示时,即。 240x100。 我已阅读 API 文档,但找不到如何控制刻度标签大小。
这可能是 OOTB 吗?
I have a basic bar chart I'm presenting in flot (5 bars, displaying the % per status).
$.plot($("#placeholder"), [
{
label: 'Failed',
data: [[0,10]],
bars: { show: true }
},
{
label: 'Passed',
data: [[1,15]],
bars: { show: true }
},
{
label: 'Not Run',
data: [[2,30]],
bars: { show: true }
},
{
label: 'Blocked',
data: [[3,5]],
bars: { show: true }
},
{
label: 'In Progress',
data: [[4,40]],
bars: { show: true }
}
],
{
xaxis: {
ticks: [[0.5, "Failed"], [1.5, "Passed"], [2.5, "Not Run"], [3.5, "Blocked"], [4.5, "In Progress"]]
},
legend: {
show: false
}
});
I'm finding the font used for the tick values on the x axis are a little too big, especially when the graph is displayed at small dimensions ie. 240x100. I've read the API documentation, but can't find how to control the tick label sizes.
Is this possible OOTB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您似乎无法通过 API 设置字体大小,但可以使用 css 来设置刻度标签的大小。
It doesn't appear you can set the font size via the API, but you can use css to set the size of the tick labels.
以下是直接来自 API 的示例:
http://flot.googlecode.com/svn/trunk /API.txt
Here's an example directly from the API:
http://flot.googlecode.com/svn/trunk/API.txt
上述两个答案不适用于最新版本的 flot,因为它们不再使用“真实”文本(而是绘制文本)。 请指定以下选项:
{xaxis: {font: size: some_number}, yaxis: {font: size: some_number}}
(将
some_number
替换为所需的磅大小)The above two answers won't work on the latest version of flot, as they no longer use 'real' text (the text is drawn instead). Instead specify these options:
{xaxis: {font: size: some_number}, yaxis: {font: size: some_number}}
(replace
some_number
with the desired size in points)我使用了以下内容:
CSS 文件/SCSS 文件
Index.html 或绘制图形区域的位置
参考:@BrentM 的上述答案
PS:我使用的是 0.8.1 之前的 Flot 版本,所以我不知道最新版本如何工作
I used the following:
CSS File/SCSS File
Index.html or place where you are plotting the graph area
Ref: @BrentM 's Answer Above
PS: I am using Flot Version prior to 0.8.1 so I dont have any idea about how latest version would work
这个解决方案适用于我的新版本的 flot。
在 yaxis 属性中,定义以下
tickFormatter()
函数:然后在 CSS 中添加以下内容:
This solution is working for me with new version of flot.
In the yaxis attributes, define the following
tickFormatter()
function :Then in the CSS add the following :