这是我的html代码,我正在做的是称为API并将数据绑定到图表,并且用于多个图表...
<ng-container *ngFor="let historyitem of historydata?.data; let i=index;">
<div class="post history_post wow fadeInUp" id="{{historyitem.id}}" *ngIf="historyitem.party?.length > 0">
<canvas baseChart width="400" height="200" [data]="chartdata" [labels]="chartlabel" [colors]="ChartColors" [legend]="true" [chartType]="ChartType"></canvas>
</div>
</ng-container>
这就是我获得API重新启动的方式,我的疑问是如何将党派绑定 ->座位与数据集或数据绑定并将党派 -> partyname绑定到标签上?我仍然很困惑如何做任何帮助?
{
"data": [
{
"id": 15,
"year": 2018,
"government": "INC,JDS",
"election_type": "GENERAL_ELECTION",
"state_government_url": "karnataka-inc-jds-2018",
"start_date": "2018-05-23",
"end_date": "2023-05-23",
"description": "The 15th Karnataka Legislative Assembly was constituted after the Karnataka Legislative Assembly elections in 2018. Polling was held on 12 May[1] for 222 constituencies out of the 224-member assembly,[2] with counting of votes and results declared on 15 May.[3] The term of the assembly is for five years.",
"likes_count": 0,
"comments_count": 0,
"share_count": 0,
"favourites_count": 0,
"liked": false,
"emoji": "NA",
"added_to_favourite": false,
"party": []
},
{
"id": 16,
"year": 2018,
"government": "BJP",
"election_type": "GENERAL_ELECTION",
"state_government_url": "karnataka-bjp-2018",
"start_date": "2018-05-17",
"end_date": "2018-05-19",
"description": "The 15th Karnataka Legislative Assembly was constituted after the Karnataka Legislative Assembly elections in 2018. Polling was held on 12 May[1] for 222 constituencies out of the 224-member assembly,[2] with counting of votes and results declared on 15 May.[3] The term of the assembly is for five years.",
"likes_count": 0,
"comments_count": 0,
"share_count": 0,
"favourites_count": 1,
"liked": false,
"emoji": "NA",
"added_to_favourite": true,
"party": []
},
{
"id": 14,
"year": 2013,
"government": "INC",
"election_type": "GENERAL_ELECTION",
"state_government_url": "karnataka-inc-2013",
"start_date": "2013-05-13",
"end_date": "2018-05-17",
"description": "INC",
"likes_count": 3,
"comments_count": 0,
"share_count": 0,
"favourites_count": 1,
"liked": true,
"emoji": "0x1F62F",
"added_to_favourite": false,
"party": [
{
"party": {
"party_name": "INC",
"party_abbervation": "Indian National Congress"
},
"seats": 122
},
{
"party": {
"party_name": "BJP",
"party_abbervation": "Bharatiya Janata Party"
},
"seats": 40
},
{
"party": {
"party_name": "JD(S)",
"party_abbervation": "Janata Dal (Secular)"
},
"seats": 40
},
{
"party": {
"party_name": "IND",
"party_abbervation": "Independent"
},
"seats": 9
},
{
"party": {
"party_name": "KJP",
"party_abbervation": "Karnataka Janatha Paksha"
},
"seats": 6
},
{
"party": {
"party_name": "BSRCP ",
"party_abbervation": "Badavara Shramikara Raitara Congress Party"
},
"seats": 4
}
]
},
{
"id": 13,
"year": 2008,
"government": "BJP",
"election_type": "GENERAL_ELECTION",
"state_government_url": "karnataka-bjp-2008",
"start_date": "2008-05-30",
"end_date": "2013-05-05",
"description": "BJP",
"likes_count": 2,
"comments_count": 0,
"share_count": 0,
"favourites_count": 1,
"liked": false,
"emoji": "NA",
"added_to_favourite": true,
"party": [
{
"party": {
"party_name": "BJP",
"party_abbervation": "Bharatiya Janata Party"
},
"seats": 117
},
{
"party": {
"party_name": "INC",
"party_abbervation": "Indian National Congress"
},
"seats": 82
},
{
"party": {
"party_name": "JD(S)",
"party_abbervation": "Janata Dal (Secular)"
},
"seats": 31
},
{
"party": {
"party_name": "IND",
"party_abbervation": "Independent"
},
"seats": 7
}
]
}
],
"code": 201,
"message": "State government information retrieved successfully."
}
对于饼图,您需要将其绑定到一组数组(一个带有标签和带有数据的第二个数组)。
由于您的数据包含多个选举数据,因此您可以向用户询问他们感兴趣的选举...然后遍历您的数据以填充一组数组(标签和数据)。
如果您想要多个图表,则会有多组数组(标签和数据)。
您可以在此处检查工作演示