ส่วนการจัดรูปแบบแบบดรอปดาวน์
Dropdown ชิ้นเป็นชิ้นการจัดรูปแบบอย่างง่ายซึ่งใช้เพื่อแสดงการแจงนับ ชนิดออบเจ็กต์จากไฟล์ capabilities.json
มีสองส่วนดรอปดาวน์ - itemDropdown และ AutoDropdown
ความแตกต่างคือสําหรับชิ้น AutoDropdown คุณต้องประกาศรายการการแจกแจงภายใต้วัตถุที่เหมาะสมในไฟล์ capabilities.json
และสําหรับชิ้น ItemDropdown ในระดับการตั้งค่าการจัดรูปแบบ
ตัวอย่าง: การดําเนินการดรอปดาวน์
ในตัวอย่างนี้ เราจะแสดงวิธีการสร้างส่วนดรอปดาวน์โดยใช้ยูทิลิตี้แบบจําลองการจัดรูปแบบ
แท็บต่อไปนี้แสดงตัวอย่างของ
วัตถุ Capabilities
แทรกส่วนย่อย JSON ต่อไปนี้ลงในไฟล์ capabilities.json
{
// ... same level as dataRoles and dataViewMappings
"objects": {
"labels": {
"properties": {
"option": {
"type": {
"enumeration": []
}
},
}
}
}
}
การจัดรูปแบบคลาสแบบจําลอง
แทรกส่วนย่อยของโค้ดต่อไปนี้ลงในไฟล์การตั้งค่า
import powerbi from "powerbi-visuals-api";
import { formattingSettings } from "powerbi-visuals-utils-formattingmodel";
const positionOptions : powerbi.IEnumMember[] = [
{value : "top", displayName : "Top"},
{value : "bottom", displayName : "Bottom"},
{value : "left", displayName : "Left"},
{value : "right", displayName : "Right"}
];
class LabelsCardSetting extends formattingSettings.SimpleCard {
name: string = "labels"; // same as capabilities object name
displayName: string = "Labels";
public option: formattingSettings.ItemDropdown = new formattingSettings.ItemDropdown({
name: "option", // same as capabilities property name
displayName: "Option",
items: positionOptions,
value: positionOptions[0]
});
public slices: formattingSettings.Slice[] = [ this.option ];
}
export class VisualSettings extends formattingSettings.Model {
public labels: LabelsCardSetting = new LabelsCardSetting();
public cards: formattingSettings.SimpleCard[] = [this.labels];
}