简体   繁体   English

浮点图与X轴标签对齐

[英]Flot Bar Graph Align Bars with X-Axis Labels

Hello I am trying to plot a bar chart with 31 days data. 您好,我正在尝试绘制31天数据的条形图。 However when I plot it, the label for each data is not directly in the center below its bar, when i set the bars to 但是,当我绘制它时,当我将条形图设置为时,每个数据的标签并不直接位于其条形图下方的中心。

align: "center"

, the first bar and last bar gets cut into half. ,第一个小节和最后一个小节被切成两半。

Here is the jsfiddle: http://jsfiddle.net/3T6qc/ 这是jsfiddle: http : //jsfiddle.net/3T6qc/

How do I set it so that i see the full bars and have the labels directly below in the center? 如何设置它,以使我看到完整的条并使标签直接位于中间的下方? Take note that I am using flot as the plotting library. 请注意,我正在使用flot作为绘图库。

Hey Here are some points to be noted about your fiddle. 嘿这里有一些关于您的提琴的注意事项。

  1. You forgot to use axis label plugin in your example.Flot doesnt have inbuild support axis label.You need to use third party plugin for it. 您在示例中忘记使用轴标签插件。Flot没有内置支持轴标签。您需要使用第三方插件。 Refer Flot plugin for axis label 请参阅Flot插件以获取轴标签

  2. For issue about your bars getting cut at edges you can refer Bar chart with align center Following updated code worked for me 有关条形图在边缘被切割的问题,可以参考条形图与居中对齐以下更新的代码对我有用

} }

if (graphMode == "month") {
$( "#hSlider" ).slider( "option", "min", 1.75 ); //add 0.75 offset
$( "#hSlider" ).slider( "option", "max", 31.75 );
$( "#hSlider" ).slider( "option", "values", [ 1, 31 ] );
for (var i = 1; i <= 31; i++) {
    if (i < day)
    {
        d.push([ i, getRandomInt(1200, 1800) ]);
    }
    else
    {
        d.push([ i, 0]);
    }
}
}

So you need to update your code a little to add offset to your bar width. 因此,您需要稍微更新代码以向条形宽度添加偏移量。

This is a known issue; 这是一个已知的问题; you'll need to work around it by adjusting the axis min and max. 您需要通过调整轴的最小值和最大值来解决它。 For example, if you have ticks at 0, 1, 2, you will want to set the min to -0.5 and the max to 2.5 to account for the bar width and centering. 例如,如果您在0、1、2处打勾,则需要将最小值设置为-0.5,将最大值设置为2.5,以说明条的宽度和居中。 This should be easy given that you already have sliders to specify those values. 鉴于您已经具有用于指定这些值的滑块,这应该很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM