用回归线分散(Scatter with regression line)

优质
小牛编辑
132浏览
2023-12-01

我们已经在Highcharts Configuration Syntax一章中看到了用于绘制图表的配置

下面给出具有带回归线的散点图的组合图的示例。

配置 (Configurations)

现在让我们看一下所采取的其他配置/步骤。

series.type

将序列类型配置为基于行/分散。 series.type决定图表的系列类型。 这里,默认值是“line”。

var series = {
   type: 'scatter'
};

例子 (Example)

highcharts_combinations_scatter.htm

<html>
   <head>
      <title>Highcharts Tutorial</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script src = "https://code.highcharts.com/highcharts.js"></script>  
   </head>
   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
      <script language = "JavaScript">
         $(document).ready(function() {  
            var title = {
               text: 'Scatter plot with regression line'   
            };
            var xAxis = {
               min: -0.5,
               max: 5.5
            };
            var yAxis = {
               min: 0
            };
            var series = [
               {
                  type: 'line',
                  name: 'Regression Line',
                  data: [[0, 1.11], [5, 4.51]],
                  marker: {
                     enabled: false
                  },
                  states: {
                     hover: {
                        lineWidth: 0
                     }
                  },
                  enableMouseTracking: false
               }, 
               {
                  type: 'scatter',
                  name: 'Observations',
                  data: [1, 1.5, 2.8, 3.5, 3.9, 4.2],
                  marker: {
                     radius: 4
                  }
               }
            ];     
            var json = {};   
            json.title = title;
            json.xAxis = xAxis;
            json.yAxis = yAxis;
            json.series = series;
            $('#container').highcharts(json);  
         });
      </script>
   </body>
</html>