在高格图

时间:2016-06-14 08:07:05

标签: jquery charts highcharts

您好,我正在为我的网站寻找一个好的图表插件。我发现了高图,这解决了我的大部分需求。现在我用这个插件构建了关注图表:



$(function () {
    $('#container').highcharts({
        chart: {
            zoomType: 'xy'
        },
        title: {
            text: 'Connect Values'
        },
        subtitle: {
            text: 'Value 1 and Value 2'
        },
        xAxis: [{
            categories: ['24.05.2015', '01.06.2015', '12.06.2015', '19.06.2015', '25.06.2015'],
            crosshair: true
        }],
        yAxis: [{ // Primary yAxis
            labels: {
                format: '{value}',
                style: {
                    color: Highcharts.getOptions().colors[1]
                }
            },
            title: {
                text: 'Value 1',
                style: {
                    color: Highcharts.getOptions().colors[1]
                }
            }
        }, { // Secondary yAxis
            title: {
                text: 'Value 2',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            labels: {
                format: '{value}',
                style: {
                    color: Highcharts.getOptions().colors[0]
                }
            },
            opposite: true
        }],
        tooltip: {
            shared: true
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 120,
            verticalAlign: 'top',
            y: 100,
            floating: true,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
        },
        series: [{
            name: 'Value 2',
            type: 'spline',
            yAxis: 1,
            data: [77, 69, 89, 84, 86],
            tooltip: {
                valueSuffix: ''
            }

        }, {
            name: 'Value 1',
            type: 'spline',
            data: [120, 118, 126, 129, 135],
            tooltip: {
                valueSuffix: ''
            }
        }]
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
&#13;
&#13;
&#13;

现在我想连接两个不同行的区域中的两个值,点到点的垂直线如下:

enter image description here

或者这也是可能的:

enter image description here

我可以在highcharts中这样做吗?或者是否有另一个图表插件,它还包含多个y轴(2个或更多)并且可以连接值?我希望得到一些帮助。

感谢。

3 个答案:

答案 0 :(得分:4)

您可以将样条线系列与列范围类型结合使用。然后设置pointWidth参数以声明每列的大小:

    series: [{
        type:'columnrange',
        pointWidth: 2,
        data: [[5,10],[4,5],[10,20],[12,15],[15,19]]
    },{
        data: [10,5,20,15,19]
    }, {
        data: [5,4,10,12,15]
    }]

示例:

答案 1 :(得分:2)

这对我很有用:

&#13;
&#13;
z-index: 99;
&#13;
        $(function () {
            $('#container').highcharts({
                chart:{
                    type: "spline",
                    zoomType: 'xy'
                },
                title: {
                    text: 'Blutdruck',
                    x: -20 //center
                },
                subtitle: {
                    text: 'Amacher Hugo | 15.08.1977 (M)',
                    x: -20
                },
                xAxis: {
                    categories: ['25.05.2015', '28.05.2015', '01.06.2015', '07.06.2015', '12.06.2015']
                },
                yAxis: {
                    title: {
                        text: 'Blutdruck mmHg'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    valueSuffix: ' mmHg'
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: [{
                    name: 'sys/dia',
                	type:'columnrange',
                    pointWidth: 2,
                    data: [[121,80],[124,95],[141,100],[122,85],[125,99]],
                },{
                    name: 'systolisch',
                    lineWidth: 0,
                    data: [121,124,141,122,125],
                    marker : {
                        enabled : true,
                        radius : 5,
                        symbol: 'triangle-down'
                    },
                }, {
                    name: 'diastolisch',
                    lineWidth: 0,
                    data: [80,95,100,85,99],
                    lineColor: null,
                    marker : {
                        enabled : true,
                        radius : 5,
                        symbol: 'triangle'
                    },
                }]
            });
        });
&#13;
&#13;
&#13;

我的系列中的<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/highcharts-more.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>已删除它。谢谢和欢呼。

答案 2 :(得分:2)

在同一行,您可以尝试Bar Chart with Connectors

$(function() {
  var chart = Highcharts.chart('container', {
    chart: {
      type: 'column'
    },
    xAxis: {
      categories: true
    },

    series: [{
      data: [10, 20, 40, 10]
    }, {
      type: 'line',
      data: [
        [0, 10],
        [1, 20]
      ],
      enableMouseTracking: false,
      showInLegend: false
    }]
  }, function(chart) {
    var series = chart.series[0],
      data = series.data,
      xAxis = series.xAxis,
      yAxis = series.yAxis;
    chart.renderer.text().attr({
      zIndex: 10,
      align: 'center'
    }).add();
  });

  $('#button').click(function () {
    chart.series[1].setData([[2, 40],[3, 10]]);
 });
});