获取在 FLOT 图表上显示的默认图表

发布于 2025-01-07 05:03:33 字数 2244 浏览 2 评论 0原文

我正在使用这个特定的 FLOT 示例来使用我们的一些数据构建图表:

http: //people.iola.dk/olau/flot/examples/ajax.html

我稍微修改了标记 - 我没有按钮,而是各种 JSON 文件的复选框,以这种方式:

<span>
  <input class="fetchSeries" type="checkbox"> Service One
  <a href="@Server.MapPath("~/Scripts/flot/servicedataone.json")"></a>
</span>

我想得到图表页面加载时预填充 JSON 文件之一。我尝试过各种方法,包括在页面加载时默认选中其中一个复选框,但没有成功。

任何帮助表示赞赏!代码如下:

 <script type="text/javascript">
    $(document).ready(function () {
        var options = {
            lines: { show: true },
            points: { show: true },
            yaxis: {
            },
            xaxis: { 
            mode: "time"
            },
            grid: { hoverable: true }
        };
        var data = [];
        var placeholder = $("#placeholder");

        $.plot(placeholder, data, options);

        // fetch one series, adding to what we got
        var alreadyFetched = {};

        $("input.fetchSeries").click(function () {
            var button = $(this);

            // find the URL in the link right next to us 
            var dataurl = button.siblings('a').attr('href');

            // then fetch the data with jQuery
            function onDataReceived (series) {
                // extract the first coordinate pair so you can see that
                // data is now an ordinary Javascript object
                var firstcoordinate = '(' + series.data[0][0] + ', ' + series.data[0][1] + ')';

                //button.siblings('span').text('Fetched ' + series.label + ', first point: ' + firstcoordinate);

                // let's add it to our current data
                if (!alreadyFetched[series.label]) {
                    alreadyFetched[series.label] = true;
                    data.push(series);
                }

                // and plot all we got
                $.plot(placeholder, data, options);
            }

            $.ajax({
                url: dataurl,
                method: 'GET',
                dataType: 'json',
                success: onDataReceived
            });
        });
     });
</script>

I'm using this particular FLOT example to build charts with some of our data:

http://people.iola.dk/olau/flot/examples/ajax.html

I've modified the markup a bit - instead of buttons, I have checkboxes for the various JSON files, in this manner:

<span>
  <input class="fetchSeries" type="checkbox"> Service One
  <a href="@Server.MapPath("~/Scripts/flot/servicedataone.json")"></a>
</span>

I would like to have the graph pre-populate with one of the JSON files when the page loads. I've tried various things, including having one of the checkboxes checked by default when the page loads, but no luck.

Any help is appreciated! Code below:

 <script type="text/javascript">
    $(document).ready(function () {
        var options = {
            lines: { show: true },
            points: { show: true },
            yaxis: {
            },
            xaxis: { 
            mode: "time"
            },
            grid: { hoverable: true }
        };
        var data = [];
        var placeholder = $("#placeholder");

        $.plot(placeholder, data, options);

        // fetch one series, adding to what we got
        var alreadyFetched = {};

        $("input.fetchSeries").click(function () {
            var button = $(this);

            // find the URL in the link right next to us 
            var dataurl = button.siblings('a').attr('href');

            // then fetch the data with jQuery
            function onDataReceived (series) {
                // extract the first coordinate pair so you can see that
                // data is now an ordinary Javascript object
                var firstcoordinate = '(' + series.data[0][0] + ', ' + series.data[0][1] + ')';

                //button.siblings('span').text('Fetched ' + series.label + ', first point: ' + firstcoordinate);

                // let's add it to our current data
                if (!alreadyFetched[series.label]) {
                    alreadyFetched[series.label] = true;
                    data.push(series);
                }

                // and plot all we got
                $.plot(placeholder, data, options);
            }

            $.ajax({
                url: dataurl,
                method: 'GET',
                dataType: 'json',
                success: onDataReceived
            });
        });
     });
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无畏 2025-01-14 05:03:33

怎么样 - 设置 $("input.fetchSeries").click 后,通过调用 $("input.fetchSeries:first").click() 触发它代码>.您需要修改 :first 部分以匹配您实际想要设置的复选框。

它看起来像这样: http://jsfiddle.net/ryleyb/bdSrc/

How about this - after you setup your $("input.fetchSeries").click, trigger it, by calling $("input.fetchSeries:first").click(). You'll want to modify the :first part to match whichever checkbox you actually want to set off.

It would look like this: http://jsfiddle.net/ryleyb/bdSrc/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文