【问题标题】:FlotChart do not work zooming modeFlotChart 在缩放模式下不起作用
【发布时间】:2014-07-14 12:46:46
【问题描述】:

我有以下示例:http://jsfiddle.net/ondra15/7mb8K/1/.
我想有两个例子(多轴和缩放)。示例缩放不能正常工作 - 如果我在图表中指出一些数据进行缩放 - 不起作用。什么都没有发生。

原始缩放(正确)解决方案在这里有效http://www.flotcharts.org/flot/examples/zooming/index.html

对我的代码有什么想法吗?谢谢

code

【问题讨论】:

  • 我在 Chrome 控制台中收到 "Uncaught TypeError: object is not a function"。认为这可能是因为没有';'在 data.push({label: this.id, data: []}) 结尾 - 但似乎没有什么不同。
  • 我尝试了这个改变,但没有帮助。请,下一个想法?谢谢
  • 有问题的代码行是data(ranges.xaxis.from, ranges.xaxis.to);你想在那里做什么?子集两个日期之间的数组?这甚至不接近正常运行的 javascript。

标签: javascript jquery char flot


【解决方案1】:

您好,我设法使用我找到的示例代码中的代码使其工作 here。我也会更新你的 jsfiddle:

<script type="text/javascript">
            var datasets = { ... };

            data = null;
            function plotByChoice(doAll) {
                data = [];
                if (doAll != null) {
                    $.each(datasets, function (key, val) {
                        data.push(val);
                    });
                }
                else {
                    $('#legend .legendCB').each(
                        function () {
                            if (this.checked) {
                                data.push(datasets[this.id]);
                            }
                            else {
                                data.push({ label: this.id, data: [] })
                            }
                        }
                    );
                }

                $.plot($("#placeholder"), data, {
                    yaxes: [{ min: 0 }, { position: "right" }],
                    xaxis: { tickDecimals: 0 },
                    legend: {
                        container: legend,
                        labelFormatter: function (label, series) {
                            var cb = '<input class="legendCB" type="checkbox" ';
                            if (series.data.length > 0) {
                                cb += 'checked="true" ';
                            }
                            cb += 'id="' + label + '" /> ';
                            cb += label;
                            return cb;
                        }
                    }, selection: { mode: "x" }
                });

                $('#legend').find("input").click(function () { setTimeout(plotByChoice, 100); });
            }

            plotByChoice(true);

            // Create the overview plot

            var overview = $.plot("#overview", data, {
                legend: {
                    show: false
                },
                series: {
                    lines: {
                        show: true,
                        lineWidth: 1
                    },
                    shadowSize: 0
                },
                xaxis: {
                    ticks: 4
                },
                yaxes: [{ min: 0 }, { position: "right" }],
                grid: {
                    color: "#999"
                },
                selection: {
                    mode: "x"
                }
            });

            $("#placeholder").bind("plotselected", function (event, ranges) {

                var options = {
                    series: {
                        lines: { show: true },
                        points: { show: true }
                    },
                    legend: { noColumns: 2 },
                    xaxis: { tickDecimals: 0 },
                    yaxis: { min: 0 },
                    selection: { mode: "x" }
                };

                var placeholder = $("#placeholder");
                placeholder.bind("plotselected", function (event, ranges) {
                    $("#selection").text(ranges.xaxis.from.toFixed(1) + " to " + ranges.xaxis.to.toFixed(1));

                    plot = $.plot(placeholder, data,
                                  $.extend(true, {}, options, {
                                      xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
                                  }));
                });


                // don't fire event on the overview to prevent eternal loop

                overview.setSelection(ranges, true);
            });

            $("#overview").bind("plotselected", function (event, ranges) {
                plot.setSelection(ranges);
            });

        </script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 2018-03-09
    • 1970-01-01
    • 2017-12-22
    • 2014-10-24
    • 1970-01-01
    相关资源
    最近更新 更多