帶有迴歸線的散點圖



下面是帶有迴歸線的散點圖示例。

我們已經在 Highcharts 配置語法 章節中看到了用於繪製圖表所用的配置。

帶有迴歸線的散點圖示例如下。

配置

現在讓我們來看看其他採取的配置/步驟。

系列

將圖表型別配置為基於散點。series.type 決定了圖表中系列的型別。這裡,預設值是“line”。

chart.addSeries(chart.createSeries()  
   .setType(Type.SCATTER)  
);  

示例

HelloWorld.java

package com.tutorialspoint.client;

import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Series;
import org.moxieapps.gwt.highcharts.client.plotOptions.LinePlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.Marker;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class HelloWorld implements EntryPoint {
   public void onModuleLoad() {
      final Chart chart = new Chart()  
         .setChartTitleText("Scatter plot with regression line");  

      chart.getXAxis()  
         .setMin(-0.5)  
         .setMax(5.5);  

      chart.getYAxis()  
         .setMin(0);  

      chart.addSeries(chart.createSeries()  
         .setName("Regression Line")  
         .setType(Series.Type.LINE)  
         .setPlotOptions(new LinePlotOptions()  
            .setMarker(new Marker()  
               .setEnabled(false)  
            )  
            .setHoverStateLineWidth(0)  
            .setEnableMouseTracking(false)  
         )  
         .setPoints(new Number[][]{  
            {0, 1.11}, {5, 4.51}  
         })  
      );  

      chart.addSeries(chart.createSeries()  
         .setName("Observations")  
         .setType(Series.Type.SCATTER)  
         .setPoints(new Number[] {  
            1, 1.5, 2.8, 3.5, 3.9, 4.2  
         })  
      );     
      RootPanel.get().add(chart);
   }
}

結果

驗證結果。

Scatter Chart with Regression Line
gwt_highcharts_combinations.htm
廣告