简体   繁体   English

在Flot中渲染图表后如何设置值?

[英]How to set values after chart is rendered in Flot?

I'm currently using Flop to display a chart on my website. 我目前正在使用Flop在我的网站上显示图表。 It's a chart with one series of data and the x-axis is set to time-mode. 这是一个包含一系列数据的图表,x轴设置为时间模式。 Now I have some buttons to change the spectrum of view ("Show all", "Show last six months", "Show last year", etc.) but I don't know how to change a specific attribute without overwriting the current plot. 现在我有一些按钮来改变视图范围(“显示所有”,“显示最近六个月”,“显示去年”等)但我不知道如何在不覆盖当前情节的情况下更改特定属性。 Currently I'm doing it this way: 目前我这样做:

$("#six-months-scope").click(function () {
    $.plot("#fd-weight-graph", data, {
        xaxis: {
            mode: "time",
            min: <?php echo $newestEntry . " - 15552000000" ?>,
            max: <?php echo $newestEntry ?>
        }
    });
});

But if I'm doing it like this, I also have to set every single option (eg set color, lines, points, etc.) and I think it's an inefficient solution. 但如果我这样做,我还必须设置每个选项(例如设置颜色,线条,点等),我认为这是一个低效的解决方案。 I just want to change the min and the max attribute. 我只想更改 min和max属性。

In addition, if I'm setting the min and the max attribute to an axis, the chart does not start at the date I set, but before and it ends after the date I set. 另外,如果我将min和max属性设置为轴,则图表不会在我设置的日期开始,而是在我设置的日期之前和之后结束。 $newestEntry is the date of the newest entry in the dataseries and I want the point of it to stick to the right end of the chart. $ newestEntry是数据集中最新条目的日期,我希望它的位置坚持到图表的右端。 I hope you understand what I mean. 我希望你明白我的意思。

Any suggestions are appreciated. 任何建议表示赞赏。

To update with new data and new axis min/max and then redraw the chart I do: 要使用新数据和新轴最小/最大值进行更新,然后重绘图表,我会执行以下操作:

 // somePlot is flot plot object saved from your initial $.plot call
 somePlot.setData(newData);
 somePlot.getOptions().xaxes[0].min = newMin;
 somePlot.getOptions().xaxes[0].max = newMax;
 somePlot.setupGrid();
 somePlot.draw();

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

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