HighCharts: draw multiple segments in a single serie?

别说谁变了你拦得住时间么 提交于 2019-12-06 06:02:10

In general, each of series required sorted data by x-values. In your case it won't be sorted. So I would suggest to separate your data into different series and then connect series using linkedTo option. for example:

$('#container').highcharts({
    series: [{
        id: 'main',
        data: [{
            x: 5,
            y: 10
        }, {
            x: 7,
            y: 10
        }]
    }, {
        data: [{
            x: 2,
            y: 12
        }, {
            x: 9,
            y: 12
        }],
        linkedTo: 'main'
    }]
});

And live demo: http://jsfiddle.net/24qf98xL/1/

It seemed like an interesting challenge: putting multiple segments into a single series. Not sure how its done in HighCharts, but I was able to accomplish it using ZingChart through the key value pairs feature.

In the series area, I included pairs of values in brackets for each line segment, where I wanted space, I placed null values.

var myChart = {
"graphset":[
    {
        "type":"line",
        "title":{
            "text":"Average Metric"
        },
        "plotarea":{
            
        },
        "scaleX":{
            
        },
        "scaleY":{
            
        },
        "plot":{
            
        },
        "series":[
            {
                "values":[[1,10],
                [2,6],
                null,
                [1.5,4],
                [3,7],
                null,
                [4.5,5],
                [6.5,7],
                null,
                [4,6],
                [5,7]],
                "text":"Apple"
            }
        ]
    }
]
};

  zingchart.render({
            id : "myChart",
            height : "300px",
            width : "100%",
            data : myChart
        });
<script src="http://www.zingchart.com/playground/lib/zingchart/zingchart-html5-min.js"></script>
<div id="myChart"></div>

I'm on the ZingChart team so if you have any questions about how we created this example please feel free to reach out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!