0

我想用 phplot 和 laravel 制作一个散点图,所以我让所有用户都有身高、体重,但他们只显示 2 点/52 个用户。我不知道为什么请帮助我。

  $users = User::all();
    $maxHeight = $users->filter()->max('height');
    $maxWeight = $users->filter()->max('weight');
    $data = array();

    foreach ($users as $user) {
        $data[] = array('', (int)$user->height, (int)$user->weight);
    }

    $plot = new PHPlot(800, 600);
    $plot->SetImageBorderType('plain');

    $plot->SetPlotType('points');
    $plot->SetDataType('data-data');

    # Main plot title:
    $plot->SetTitle('Scatterplot (User plot)');

    $plot->SetXTitle('weight');
    $plot->SetYTitle('height');
    $plot->SetDataValues($data);

    # Need to set area and ticks to get reasonable choices.
    $plot->SetPlotAreaWorld(0, 0, $maxWeight, $maxHeight);
    $plot->SetXTickIncrement(5);
    $plot->SetYTickIncrement(5);

    $plot->SetYTickPos('yaxis');


    # Turn on 4 sided borders, now that axes are inside:
    $plot->SetPlotBorderType('full');

    # Draw both grids:
    $plot->SetDrawXGrid(True);
    $plot->SetDrawYGrid(True);  # Is default

    $plot->SetIsInline(true);
    $plot->SetOutputFile("test.png");

    $plot->DrawGraph();

然后他们只用 2 个用户显示 2 个点,但不是全部: 图片

4

0 回答 0