3

我试图建立一个组合的散点图和折线图。目前散点图很好,当我添加线时,它们向右旋转 90 度,所以它们是垂直的而不是水平的。我一生都无法弄清楚为什么,所以如果有人有任何建议,那就太棒了。

下面的代码是完整的功能,现在忽略它的名称 -NOT- 样条图(我真的应该改变它)。

function cg_graphs_spline_plot($surgeonname, $plotpoint, $nnotnullsingletotal, $surgeonplots, $baseline, $gsettings){

  /*Build the binomial curve plots*/
  $binomloop = $gsettings['maxmin'][0]['Max'] + 1;
  for($i = 1; $i <= $binomloop; $i++){
    $upperalert = cg_graphs_get_binomial($baseline, $i, 0.995);
    $loweralert = cg_graphs_get_binomial($baseline, $i, 0.005);
    $Ualert[] = ($upperalert['upper'] * 100);
    $Lalert[] = ($loweralert['lower'] * 100);
    //$upperalarm = cg_graphs_get_binomial($baseline, $i, 0.9995);
    //$loweralarm = cg_graphs_get_binomial($baseline, $i, 0.0005);
    //$Ualarm[] = ($upperalarm['upper'] * 100);
    //$Lalarm[] = ($loweralarm['lower'] * 100);
  }
    unset($Ualert[0]); //delete the leading 0 value
    unset($Lalert[0]); //delete the leading 0 value
    mmi_watchdog('plotting alarm upper', '', $Ualert);
    mmi_watchdog('plotting alarm lower', '', $Lalert);
    //mmi_watchdog('plotting alarm upper', '', $Ualarm);
    //mmi_watchdog('plotting alarm lower', '', $Lalarm);

  /* Create the pData object */
  $myData = new pData();
  $myData->addPoints(array($plotpoint), "preSurgeons"); //Y pos just has to match pos of X
  $myData->addPoints(array($nnotnullsingletotal), "pSurgeon"); //array pos matches, so the

  foreach($surgeonplots['ops'] as $op){
    $myData->addPoints($op, "Surgeons");
  }

  foreach($surgeonplots['reop'] as $reop){
    $baselineplots[] = $baseline;
    $myData->addPoints($reop, "reSurgeons");
  }
  $myData->addPoints($baselineplots, "baseline"); //add baseline for line graph
  /** plot binomials */
  $myData->addPoints($Ualert, "Ualert"); //add upper alert
  $myData->addPoints($Lalert, "Lalert"); //add lower alert
  //$myData->addPoints($Ualarm, "Ualarm"); //add upper alarm
  //$myData->addPoints($Lalarm, "Lalarm"); //add lower alarm

  /* Create the X axis and the binded series */
  $myData->setSerieOnAxis("Surgeons",0);
  $myData->setSerieOnAxis("pSurgeon",0);
  $myData->setSerieOnAxis("Ualert",0);
  $myData->setSerieOnAxis("Lalert",0);
  $myData->setSerieOnAxis("baseline",0);
  $myData->setAxisName(0,$gsettings['axisXlabel']); //Number of operations -- removed for now
  $myData->setAxisXY(0,AXIS_X);
  $myData->setAxisPosition(0,AXIS_POSITION_BOTTOM);

  /* Create the Y axis and the binded series */
  $myData->setSerieOnAxis("reSurgeons",1);
  $myData->setSerieOnAxis("preSurgeons",1);
  $myData->setAxisName(1,$gsettings['axisYlabel']);
  $myData->setAxisXY(1,AXIS_Y);
  $myData->setAxisUnit(1,"%");
  $myData->setAxisPosition(1,AXIS_POSITION_LEFT);

  /* Create All surgeons scatter chart binding */
  $myData->setScatterSerie("Surgeons","reSurgeons",0);
  $myData->setScatterSerieDescription(0,"All Surgeons");
  $myData->setScatterSerieColor(0,array("R"=>255,"G"=>69,"B"=>0));

  /* Create Single Surgions scatter point */
  $myData->setScatterSerie("pSurgeon","preSurgeons",1);
  $myData->setScatterSerieDescription(1, $surgeonname);
  $myData->setScatterSerieColor(1,array("R"=>0,"G"=>191,"B"=>255));

  /*unset the baseline for the first set*/
  $myData->setSerieDrawable (array("baseline", "Ualert", "Lalert", "Ualarm", "Lalarm"), FALSE); 
  /* Create the pChart object */
  $myPicture = new pImage(847,304,$myData);

  $myPicture->drawGradientArea(0,0,847,304,DIRECTION_VERTICAL,array("StartR"=>47,"StartG"=>47,"StartB"=>47, "EndR"=>17,"EndG"=>17,"EndB"=>17,"Alpha"=>100));
  $myPicture->drawGradientArea(0,250,847,304,DIRECTION_VERTICAL,array("StartR"=>47,"StartG"=>47,"StartB"=>47, "EndR"=>27,"EndG"=>27,"EndB"=>27,"Alpha"=>100));
  $myPicture->drawLine(0,249,847,249,array("R"=>0,"G"=>0,"B"=>0));
  $myPicture->drawLine(0,250,847,250,array("R"=>70,"G"=>70,"B"=>70));

  /* Write the picture title */ 
  $myPicture->setFontProperties(array("FontName"=>drupal_get_path('module', 'cg_graphs')."/pChart/fonts/pf_arma_five.ttf","FontSize"=>6));
  $myPicture->setFontProperties(array("R"=>255,"G"=>255,"B"=>255));
  $myPicture->drawText(423,14,$gsettings['title'],array("R"=>255,"G"=>255,"B"=>255,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));

  /* Set the graph area */
  $myPicture->setGraphArea(58,27,816,228);

  /* Draw a rectangle */
  $myPicture->drawFilledRectangle(57,27,816,228,array("R"=>0,"G"=>0,"B"=>0,"Dash"=>TRUE,"DashR"=>0, "DashG"=>51,"DashB"=>51,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));

  /* Turn on shadow computing */ 
  $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));

  /* Create the Scatter chart object */
  $myScatter = new pScatter($myPicture,$myData);

  /* Draw the scale */
  $myScatter->drawScatterScale(array('LabelRotation' => 90, "Mode" => SCALE_MODE_MANUAL, "XMargin"=>4, "Pos" => SCALE_POS_LEFTRIGHT, "ManualScale" => $gsettings['maxmin'], 'Factors' => array(20)));
  $myScatter->drawScatterLegend(640,266,array("Mode"=>LEGEND_VERTICAL ,"Style"=>LEGEND_NOBORDER, "Family"=>LEGEND_FAMILY_LINE));
  /* Draw a scatter plot chart */
  $myScatter->drawScatterPlotChart();
  /*Draw Baseline chart*/
  $myData->setSerieDrawable (array("pSurgeon", "Surgeons", "preSurgeons", "reSurgeons"), FALSE);
  $myData->setSerieDrawable (array("baseline", "Ualert", "Lalert"), TRUE);

  /* plot lines */
  $myPicture->drawLineChart(array("DisplayValues"=>FALSE,"DisplayColor"=>DISPLAY_AUTO));

  /* Write the 0 line */
  $myPicture->drawThreshold(0,array("WriteCaption"=>TRUE));
  /* Add a border to the picture */
  $myPicture->drawRectangle(0,0,846,303,array("R"=>204,"G"=>204,"B"=>204));

  $myData->setSerieDrawable (array("reSurgeons"), FALSE);

  /* Set serie settings */
  $myData->setSerieDescription("baseline","Average Baseline");
  $myData->setSerieDescription("Ualert","Upper Alert Line");
  $myData->setSerieDescription("Lalert","Lower Alert Line");
  $myData->setSerieDescription("Ualarm","Upper Alarm Line");
  $myData->setSerieDescription("Lalarm","Lower Alert Line");

  $myPicture->drawLegend(540,266,array("Mode"=>LEGEND_VERTICAL ,"Style"=>LEGEND_NOBORDER, "Family"=>LEGEND_FAMILY_LINE));

  /* Render the picture (choose the best way) */
  $imagename = str_replace(' ', '-', $surgeonname);
  $myPicture->render(drupal_get_path('module', 'cg_graphs')."/pChart/examples/pictures/".$imagename."-".$gsettings['name'].".png");
}

图形图像

4

1 回答 1

1

好的,所以想通了,我错过了折线图的绘制比例。

新代码:

function cg_graphs_spline_plot($surgeonname, $plotpoint, $nnotnullsingletotal, $surgeonplots, $baseline, $gsettings){

      /*Build the binomial curve plots*/
      $binomloop = $gsettings['maxmin'][0]['Max'] + 1;
      $x = 0;
      for($i = 1; $i <= $binomloop; $i++){
        $upperalert = cg_graphs_get_binomial($baseline, $i, 0.995);
        $loweralert = cg_graphs_get_binomial($baseline, $i, 0.005);
        $lineXaxis[] = $x; //build values for the line x axis
        $baselineplots[] = $baseline; //build values for the baseline
        $Ualert[] = ($upperalert['upper'] * 100);
        $Lalert[] = ($upperalert['lower'] * 100);
        $upperalarm = cg_graphs_get_binomial($baseline, $i, 0.9995);
        $loweralarm = cg_graphs_get_binomial($baseline, $i, 0.0005);
        $Ualarm[] = ($upperalarm['upper'] * 100);
        $Lalarm[] = ($upperalarm['lower'] * 100);
        $x++;
      }
        unset($Ualert[0]); //delete the leading 0 value
        unset($Lalert[0]); //delete the leading 0 value
        mmi_watchdog('plotting alarm upper', '', $Ualert);
        mmi_watchdog('plotting alarm lower', '', $Lalert);
        //mmi_watchdog('plotting alarm upper', '', $Ualarm);
        //mmi_watchdog('plotting alarm lower', '', $Lalarm);

      /* Create the pData object */
      $myData = new pData();
      $myData->addPoints(array($plotpoint), "preSurgeons"); //Y pos just has to match pos of X
      $myData->addPoints(array($nnotnullsingletotal), "pSurgeon"); //array pos matches, so the

      foreach($surgeonplots['ops'] as $op){
        $myData->addPoints($op, "Surgeons");
      }

      foreach($surgeonplots['reop'] as $reop){
        $myData->addPoints($reop, "reSurgeons");
      }
      $myData->addPoints($baselineplots, "baseline"); //add baseline for line graph
      /** plot binomials */
      $myData->addPoints($Ualert, "Ualert"); //add upper alert
      $myData->addPoints($Lalert, "Lalert"); //add lower alert
      $myData->addPoints($Ualarm, "Ualarm"); //add upper alarm
      $myData->addPoints($Lalarm, "Lalarm"); //add lower alarm

      /* Create the X axis and the binded series */
      $myData->setSerieOnAxis("Surgeons",0);
      $myData->setSerieOnAxis("pSurgeon",0);
      $myData->setSerieOnAxis("Ualert",1);
      $myData->setSerieOnAxis("Lalert",1);
      $myData->setSerieOnAxis("baseline",1);
      $myData->setAxisName(0,$gsettings['axisXlabel']); //Number of operations -- removed for now
      $myData->setAxisXY(0,AXIS_X);
      $myData->setAxisPosition(0,AXIS_POSITION_BOTTOM);

      /* Create the Y axis and the binded series */
      $myData->setSerieOnAxis("reSurgeons",1);
      $myData->setSerieOnAxis("preSurgeons",1);
      $myData->setAxisName(1,$gsettings['axisYlabel']);
      $myData->setAxisXY(1,AXIS_Y);
      $myData->setAxisUnit(1,"%");
      $myData->setAxisPosition(1,AXIS_POSITION_LEFT);

      /* Create All surgeons scatter chart binding */
      $myData->setScatterSerie("Surgeons","reSurgeons",0);
      $myData->setScatterSerieDescription(0,"All Surgeons");
      $myData->setScatterSerieColor(0,array("R"=>255,"G"=>69,"B"=>0));

      /* Create Single Surgions scatter point */
      $myData->setScatterSerie("pSurgeon","preSurgeons",1);
      $myData->setScatterSerieDescription(1, $surgeonname);
      $myData->setScatterSerieColor(1,array("R"=>0,"G"=>191,"B"=>255));

      /*unset the baseline for the first set*/
      $myData->setSerieDrawable (array("baseline", "Ualert", "Lalert", "Ualarm", "Lalarm"), FALSE); 
      /* Create the pChart object */
      $myPicture = new pImage(847,304,$myData);

      $myPicture->drawGradientArea(0,0,847,304,DIRECTION_VERTICAL,array("StartR"=>47,"StartG"=>47,"StartB"=>47, "EndR"=>17,"EndG"=>17,"EndB"=>17,"Alpha"=>100));
      $myPicture->drawGradientArea(0,250,847,304,DIRECTION_VERTICAL,array("StartR"=>47,"StartG"=>47,"StartB"=>47, "EndR"=>27,"EndG"=>27,"EndB"=>27,"Alpha"=>100));
      $myPicture->drawLine(0,249,847,249,array("R"=>0,"G"=>0,"B"=>0));
      $myPicture->drawLine(0,250,847,250,array("R"=>70,"G"=>70,"B"=>70));

      /* Write the picture title */ 
      $myPicture->setFontProperties(array("FontName"=>drupal_get_path('module', 'cg_graphs')."/pChart/fonts/pf_arma_five.ttf","FontSize"=>6));
      $myPicture->setFontProperties(array("R"=>255,"G"=>255,"B"=>255));
      $myPicture->drawText(423,14,$gsettings['title'],array("R"=>255,"G"=>255,"B"=>255,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));

      /* Set the graph area */
      $myPicture->setGraphArea(58,27,816,228);

      /* Draw a rectangle */
      $myPicture->drawFilledRectangle(57,27,816,228,array("R"=>0,"G"=>0,"B"=>0,"Dash"=>TRUE,"DashR"=>0, "DashG"=>51,"DashB"=>51,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));

      /* Turn on shadow computing */ 
      $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));

      /* Create the Scatter chart object */
      $myScatter = new pScatter($myPicture,$myData);

      /* Draw the scale */
      $myScatter->drawScatterScale(array("Mode" => SCALE_MODE_MANUAL, "XMargin"=>4, "Pos" => SCALE_POS_LEFTRIGHT, "ManualScale" => $gsettings['maxmin'], 'Factors' => array(20)));
      $myScatter->drawScatterLegend(640,266,array("Mode"=>LEGEND_VERTICAL ,"Style"=>LEGEND_NOBORDER, "Family"=>LEGEND_FAMILY_LINE));
      /* Draw a scatter plot chart */
      $myScatter->drawScatterPlotChart();
      /*Draw Baseline chart*/
      $myData->setSerieDrawable (array("pSurgeon", "Surgeons", "preSurgeons", "reSurgeons"), FALSE);
      $myData->setSerieDrawable (array("baseline", "Ualert", "Lalert", "Ualarm", "Lalarm"), TRUE);

      /* plot lines */
      $myData->addPoints($lineXaxis,"Labels");
      $myData->setSerieDescription("Labels","My labels");
      $myData->setAbscissa("Labels");

      $myPicture->drawScale(array("Mode" => SCALE_MODE_MANUAL, "XMargin"=>4, "Pos" => SCALE_POS_LEFTRIGHT, "ManualScale" => $gsettings['maxmin'], 'Factors' => array(20), 'RemoveXAxis' => TRUE));
      $myPicture->drawLineChart(array("DisplayValues"=>FALSE,"DisplayColor"=>DISPLAY_AUTO));

      /* Add a border to the picture */
      $myPicture->drawRectangle(0,0,846,303,array("R"=>204,"G"=>204,"B"=>204));

      /* Set serie settings */
      $myData->setSerieDescription("baseline","Average Baseline");
      $myData->setSerieDescription("Ualert","Upper Alert Line");
      $myData->setSerieDescription("Lalert","Lower Alert Line");
      $myData->setSerieDescription("Ualarm","Upper Alarm Line");
      $myData->setSerieDescription("Lalarm","Lower Alert Line");

      $myPicture->drawLegend(540,266,array("Mode"=>LEGEND_VERTICAL ,"Style"=>LEGEND_NOBORDER, "Family"=>LEGEND_FAMILY_LINE));

      /* Render the picture (choose the best way) */
      $imagename = str_replace(' ', '-', $surgeonname);
      $myPicture->render(drupal_get_path('module', 'cg_graphs')."/pChart/examples/pictures/".$imagename."-".$gsettings['name'].".png");
    }
于 2013-05-23T12:16:19.353 回答