javascript - 如何在 highstock 基本线图上绘制多条线?

标签 javascript jquery highcharts

我想为您的图书馆的此类图表绘制多条线:http://www.highcharts.com/stock/demo/basic-line

我在互联网上找到了这个示例:http://jsfiddle.net/yildirim_timur/Hb3Q7/

下面你可以看到我的 html 文件。我尝试做几件事但没能成功。我怎样才能使我的图表也能够绘制多条线? (适用于 ipad 应用程序项目)

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Senior Project Timur Aykut YILDIRIM - IH Technology</title>
        <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
        <link rel="stylesheet" type="text/css" href="/Users/ihtechnology/Desktop/chart_deneme/css/normalize.css">
        <link rel="stylesheet" type="text/css" href="/Users/ihtechnology/Desktop/chart_deneme/css/result-light.css">
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet"/>
        <script type='text/javascript'>
            var serviceDataURL = "http://xx.xx.xxx.xxx:83/get_item_data_ios?generic=";

            function setDictionary(x){
                return x;
            } // no need for this method

            var dict = "web service query string will be here";

            $(function() {
                $.getJSON(serviceDataURL.concat(dict), function(data) {
                    // Create the chart
                    window.chart = new Highcharts.StockChart({
                        chart : {
                            renderTo : 'container'
                        },
                        navigation: {
                            buttonOptions: {
                                enabled: false,
                                width: 60
                            }
                        },
                        rangeSelector : {
                            buttonSpacing: 20,
                            buttonTheme: { // styles for Q,Y,YTD,ALL buttons
                                fill: 'none',
                                stroke: 'none',
                                'stroke-width': 15,
                                style: {
                                    color: '#039',
                                    fontWeight: 'bold'
                                },
                                states: {
                                    hover: {},
                                    select: {
                                        fill: '#039',
                                            style: {
                                                color: 'white'
                                            }
                                    }
                                }
                            },
                            selected : 3, // 3=ALL buton at first
                            inputDateFormat: '%Y-%m-%d',
                            inputEditDateFormat: '%Y-%m-%d',
                            buttons:[
                                {
                                    type: 'month',
                                    count: 3,
                                    text: 'QQ'
                                },

                                {
                                    type: 'year',
                                    count: 1,
                                    text: 'YY'
                                },

                                {
                                    type: 'ytd',
                                    text: 'YTD'
                                },

                                {
                                    type: 'all',
                                    text: 'ALL'
                                },
                            ]
                        },
                        title : {
                            text : 'My Total Market'
                        },
                        credits: {
                            text: " ",
                            href: " ",
                        },
                        series : [{
                            name : 'Total Market',
                            data : arr,
                            tooltip: {
                                valueDecimals: 2
                            }
                        }],
                        exporting: {
                            enabled: false
                        }
                    }, function(chart){
                            // apply the date pickers
                            setTimeout(function(){
                                $('input.highcharts-range-selector').attr('readonly',1); // burda webviewı engelledik
                                $('input.highcharts-range-selector', $('#'+chart.options.chart.renderTo))
                            },0)
                        });
                });

            });

                //]]>
        </script>
    </head>
    <body>
        <div id="container" style="height: 500px; min-width: 500px;"></div>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
        <script src="http://code.highcharts.com/stock/highstock.js"></script>
        <script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
    </body>
</html>

最佳答案

现在你有:

                    series : [{
                        name : 'Total Market',
                        data : arr,
                        tooltip: {
                            valueDecimals: 2
                        }
                    }]

所以系列中只有一个对象。如果你想要多个系列,那么应该是这样的:

                    series : [{
                        name : 'Total Market I',
                        data : arr_1,
                        tooltip: {
                            valueDecimals: 2
                        }
                    },{
                        name : 'Total Market II',
                        data : arr_2,
                        tooltip: {
                            valueDecimals: 2
                        }
                    }]

编辑:

要添加多个系列,请将它们推送到数组:

var mySeries = [];

mySeries.push({
    name : 'Total Market I',
    data : arr_1
});
mySeries.push({
    name : 'Total Market II',
    data : arr_2
});
mySeries.push({
    name : 'Total Market III',
    data : arr_3
});

然后创建图表:

series: mySeries

关于javascript - 如何在 highstock 基本线图上绘制多条线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23927248/

相关文章:

javascript - 尝试实现 svg :clipPath but end up with almost a blank screen

javascript - 拼接对象的属性?

javascript - 将 jQuery 与 Shadow dom 结合使用

javascript - 单击下拉菜单时将文本粘贴到输入框中

html - 半圆 donut chart highchart,里面嵌入了文本

javascript - Dynamic Highcharts 未更新

函数内的 JavaScript if 语句运行另一个函数

javascript - AWS Lambda 函数多次处理相同的 dynamodb 流。我错过了什么?

javascript - 使用 ajax 时 asp mvc 显示不更新

javascript - 如何让 Highchart 出现在 HTML 页面中?