လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> imagefloteredarc ကိုသုံးပြီးမျိုးစုံအပိုင်းအစများ၏ရှုပ်ထွေးသော arc charts ဆွဲနည်းကိုဘယ်လိုရေးမလဲ။ ဂရပ်ဖစ် visualing one တစ်ဆယ့်တစ်ဆင့်တွင်နေရာဖြစ်သည်

imagefloteredarc ကိုသုံးပြီးမျိုးစုံအပိုင်းအစများ၏ရှုပ်ထွေးသော arc charts ဆွဲနည်းကိုဘယ်လိုရေးမလဲ။ ဂရပ်ဖစ် visualing one တစ်ဆယ့်တစ်ဆင့်တွင်နေရာဖြစ်သည်

M66 2025-06-12

PHP တွင် Iffepefeledarc () သည်အလွန်အစွမ်းထက်သော function တစ်ခုဖြစ်သည်။ အဓိကအားဖြင့် arc charts ဆွဲရန်အသုံးပြုသည်။ Segments မျိုးစုံနှင့်ရှုပ်ထွေးသောကွေးကောက်ဇယားကိုပြရန်လိုအပ်သည့်အခါ၎င်းသည်အလွန်အသုံးဝင်သောကိရိယာတစ်ခုဖြစ်သည်မှာသေချာသည်။ ဤဆောင်းပါးသည် accment arc charts ဆွဲရန် Idefreatedarc () function ကိုမည်သို့အသုံးပြုရမည်ကိုပြသပါလိမ့်မည်။

1 ။ Idefreatedarc () function ကိုမိတ်ဆက်ပါ

Idefefelect () သည် ARC ကိုဆွဲဆောင်ရန်အသုံးပြုသော GD စာကြည့်တိုက်တွင် function တစ်ခုဖြစ်သည်။ ၎င်း၏အခြေခံ syntax သည်အောက်ပါအတိုင်းဖြစ်သည် -

 imagefilledarc(resource $image, int $cx, int $cy, int $width, int $height, int $start, int $end, int $color, int $style)
  • $ Image : ပုံရိပ်အရင်းအမြစ်ကိုပစ်မှတ်ထားသည်။

  • $ CX, $ cy - စက်ဝိုင်း၏ဗဟို၏သွဒီနိတ်။

  • $ width, $ အမြင့် : arc area ရိယာ၏အနံနှင့်အမြင့်။

  • $ start : arc ၏စတင်ထောင့်။

  • $ end : arc ၏အဆုံးထောင့်။

  • $ အရောင် : arc ၏အပြည့်အရောင်။

  • $ စတိုင် : arc ဖြည့်စွက်စတိုင်။

ဤလုပ်ဆောင်ချက်သည် Pie Charts, Circular တိုးတက်မှုအရောင်းဆိုင်များ, ရှုပ်ထွေးသောစာရင်းအင်းဆိုင်ရာဇယားများစသည်တို့ကိုပုံဆွဲရန်အလွန်သင့်လျော်သည်။

2 ။ အခြေခံဇယားတစ်ခုဖန်တီးပါ

ပထမ ဦး စွာ ARC ကိုဘယ်လိုဆွဲရမယ်ဆိုတာကိုပြသထားတဲ့ရိုးရှင်းတဲ့ဇယားတစ်ခုဖန်တီးကြပါစို့။ ကျွန်ုပ်တို့သည် arc ကို 0 မှ 180 ဒီဂရီအထိ IDEFFEESTARTARC () နှင့်အရောင်ကိုသတ်မှတ်ပါလိမ့်မည်။

 <?php
// ပုံရိပ်အရင်းအမြစ်တစ်ခုဖန်တီးပါ
$image = imagecreatetruecolor(400, 400);

// အရောင်များကိုသတ်မှတ်ပါ
$bgColor = imagecolorallocate($image, 255, 255, 255); // အဖြူရောင်နောက်ခံ
$arcColor = imagecolorallocate($image, 255, 0, 0); // အနီရောင် arc

// နောက်ခံအရောင်ကိုဖြည့်ပါ
imagefill($image, 0, 0, $bgColor);

// arc ဆွဲပါ
imagefilledarc($image, 200, 200, 300, 300, 0, 180, $arcColor, IMG_ARC_PIE);

// output ကိုပုံ
header('Content-Type: image/png');
imagepng($image);

// မှတ်ဥာဏ်အခမဲ့မှတ်ဥာဏ်
imagedestroy($image);
?>

အထက်ပါကုဒ်တွင် 400x400 ၏ပုံရိပ်ကိုဖန်တီးပြီးနောက်ခံကိုသတ်မှတ်သည်။ ထို့နောက်ကျွန်ုပ်တို့သည် arc ကို 0 မှ 180 ဒီဂရီအထိအနီရောင်ဖြင့်ဆွဲယူသည်။

3 ။ မျိုးစုံ segmented arc ဇယားဆွဲပါ

Segments မျိုးစုံ၏ရှုပ်ထွေးသော arc ဇယားဆွဲရန် arc ကို segments အမျိုးမျိုးသို့ခွဲထုတ်ရန်လိုအပ်သည်။ အစိတ်အပိုင်းတစ်ခုစီသည်ကွဲပြားခြားနားသောစတင်သည့်ထောင့်များရှိသည်။ ဤတွင်ပိုမိုရှုပ်ထွေးသောဥပမာတစ်ခုမှာ seggent လေးခုပါသောစက်ဝိုင်းတစ်ခုကိုဆွဲယူပါမည်။

 <?php
// ပုံရိပ်အရင်းအမြစ်တစ်ခုဖန်တီးပါ
$image = imagecreatetruecolor(400, 400);

// အရောင်များကိုသတ်မှတ်ပါ
$bgColor = imagecolorallocate($image, 255, 255, 255); // အဖြူရောင်နောက်ခံ
$colors = [
    imagecolorallocate($image, 255, 0, 0),   // နီသော
    imagecolorallocate($image, 0, 255, 0),   // စိမ်းလန်းသော
    imagecolorallocate($image, 0, 0, 255),   // ပြာသော
    imagecolorallocate($image, 255, 255, 0)  // ဝါသော
];

// နောက်ခံအရောင်ကိုဖြည့်ပါ
imagefill($image, 0, 0, $bgColor);

// ဒေတာနှင့်အဓိပ္ပါယ်(တန်ဖိုးတစ်ခုစီသည်သက်ဆိုင်ရာအစိတ်အပိုင်း၏ထောင့်ကိုကိုယ်စားပြုသည်)
$data = [40, 30, 60, 90]; // ပေါင်းလဒ်သည် 220 ဒီဂရီ

// 计算每个分段的起始和结束角ဒီဂရီ
$startAngle = 0;
foreach ($data as $i => $value) {
    $endAngle = $startAngle + $value;
    imagefilledarc($image, 200, 200, 300, 300, $startAngle, $endAngle, $colors[$i], IMG_ARC_PIE);
    $startAngle = $endAngle;
}

// output ကိုပုံ
header('Content-Type: image/png');
imagepng($image);

// မှတ်ဥာဏ်အခမဲ့မှတ်ဥာဏ်
imagedestroy($image);
?>

ဤဥပမာတွင် ဒေါ်လာဒေတာ များရှိတန်ဖိုးများကို အခြေခံ. တန်ဖိုးများကို အခြေခံ. အစိတ်အပိုင်းများကိုဆွဲဆောင်သည် (တန်ဖိုးတစ်ခုစီသည် arc ၏ထောင့်ကိုကိုယ်စားပြုသည်) ။ အစိတ်အပိုင်းတစ်ခုစီ၏အရောင်သည်ကြိုတင်သတ်မှတ်ထားသောအရောင်တပ်ဆင်မှုတစ်ခုဖြစ်သည်။

4 ။ URL မှတစ်ဆင့်ဒေတာများကို dynamically load

ဇယားကိုပိုမိုပြောင်းလွယ်ပြင်လွယ်စေရန် URLs မှတစ်ဆင့်ကွဲပြားခြားနားသောအချက်အလက်များကိုကျွန်ုပ်တို့ပြောင်းလဲနိုင်သည်။ ဒေတာသည် URL မှလာသည်ဆိုပါစို့။ အချက်အလက်များကို JSON format ဖြင့်ပြုလုပ်သည်ဆိုပါစို့။ PHP ၏ File_Get_Contense () function ကို သုံး. ၎င်းကို PHP array သို့ JSONS_DECode () သို့ပြောင်းရန် PHP array သို့ပြောင်းလဲနိုင်သည်။ ဤတွင်ရိုးရှင်းသောဥပမာတစ်ခုဖြစ်သည်။

 <?php
// မှ URL ရယူ JSON အချက်များ
$dataUrl = 'https://m66.net/data.json'; // 假设အချက်များ存放在这个 URL
$jsonData = file_get_contents($dataUrl);
$data = json_decode($jsonData, true);

// ပုံအရင်းအမြစ်များကိုဖန်တီးပါ
$image = imagecreatetruecolor(400, 400);

// အရောင်များကိုသတ်မှတ်ပါ
$bgColor = imagecolorallocate($image, 255, 255, 255); // အဖြူရောင်နောက်ခံ
$colors = [
    imagecolorallocate($image, 255, 0, 0),   // နီသော
    imagecolorallocate($image, 0, 255, 0),   // စိမ်းလန်းသော
    imagecolorallocate($image, 0, 0, 255),   // ပြာသော
    imagecolorallocate($image, 255, 255, 0)  // ဝါသော
];

// နောက်ခံအရောင်ကိုဖြည့်ပါ
imagefill($image, 0, 0, $bgColor);

// 计算每个分段的起始和结束角ဒီဂရီ
$startAngle = 0;
foreach ($data as $i => $value) {
    $endAngle = $startAngle + $value;
    imagefilledarc($image, 200, 200, 300, 300, $startAngle, $endAngle, $colors[$i % count($colors)], IMG_ARC_PIE);
    $startAngle = $endAngle;
}

// output ကိုပုံ
header('Content-Type: image/png');
imagepng($image);

// မှတ်ဥာဏ်အခမဲ့မှတ်ဥာဏ်
imagedestroy($image);
?>

ဤကုဒ်တွင်ဒေတာများကို URL တွင်သိမ်းဆည်းထားပြီး JSON format ရှိဒေတာများကို file_get_contents () function မှတဆင့်ရရှိသည်။ ထို့နောက်ဤအချက်အလက်များအပေါ် အခြေခံ. ARC segments များစွာကို dynamically ရေးဆွဲနေကြသည်။ သတိပြုသင့်သည်မှာကျွန်ုပ်တို့သည်ပိုမိုဒေတာ segmemment နှင့်ရင်ဆိုင်ဖြေရှင်းနိုင်ရန်အရောင်ခင်းကျင်းမှုတွင်ရိုးရှင်းသောကွင်းဆက်ကိုပြုလုပ်ခဲ့သည်။