gpt4 book ai didi

javascript - 向图表添加数据

转载 作者:行者123 更新时间:2023-11-30 18:13:53 36 4
gpt4 key购买 nike

查看 Api 2.0p5 和图表。

我正在寻找吞吐量图表的变体,基本上有...

  • 过去 12 个月的底部
  • 图表左侧的总数
  • 故事和缺陷计数的堆叠列
  • 脊柱线穿过故事点,点的次要 y 轴

所以到目前为止,我的拉力赛应用程序中的所有这些都可以正常工作,除了我所有的数字目前都是硬编码的。我如何才能将这些信息正确地放入我的图表中?

我看到了一个使用商店的例子,但看起来很古怪,老实说,我不知道我在哪里看到它来尝试和复制。

代码如下,如果有人有想法或想法,我将不胜感激:

    <!DOCTYPE html>
<html>

<head>
<meta http-equiv="refresh" content="240" />
<title>Throughput Chart</title>
<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0p5/sdk.js?debug=true"></script>
<script type="text/javascript">

Rally.onReady(function () {

Ext.create('Ext.Container', {
items: [
{
xtype: 'rallychart',
height: 400,
series: [{
name: 'Defect Count',
data: [2, 2, 3, 2, 1, 4, 2, 3, 5, 3, 5, 4]
}, {
name: 'Story Count',
data: [3, 4, 4, 2, 5, 3, 4, 5, 6, 3, 4, 8]
}, {
name: 'Story Points',
color: '#89A54E',
type: 'spline',
yAxis: 1,
data: [55, 34, 50, 31, 44, 61, 55, 22, 50, 48, 34, 44]
}],
chartConfig: {
chart: {
type: 'column'
},
title: {
text: 'Kanban State Counts',
align: 'center'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: [{
title: {
text: 'Count'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
}
}
},
{
opposite: true,
title: {
text: 'Story Points'
}
}],
}
}
],
renderTo: Ext.getBody().dom
});

});
</script>



<style type="text/css">
</style>
</head>
<body>
</body>
</html>

最佳答案

这是一个使用 WsapiDataStore 中的用户故事数据的基本示例。该代码只是按 ScheduleState 汇总了故事,并将计数添加到 Ext.data.store。然后应用程序使用 Rally.ui.chart.ChartView 组件在条形图中显示按计划状态的故事计数。

<!DOCTYPE html>
<html>
<head>
<title>ChartExample</title>

<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0p5/sdk.js"></script>

<script type="text/javascript">
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',

launch: function() {
Ext.create('Rally.data.WsapiDataStore', {
model: 'UserStory',
autoLoad: true,
listeners: {
load: this._onDataLoaded,
scope: this
}
});
},

_onDataLoaded: function(store, data) {
var records = [];
var scheduleStateGroups = ["Defined","In-Progress","Completed","Accepted"]

// State count variables
var definedCount = 0;
var inProgressCount = 0;
var completedCount = 0;
var acceptedCount = 0;

// Loop through returned data and group/count by ScheduleState
Ext.Array.each(data, function(record) {
//Perform custom actions with the data here
//Calculations, etc.

scheduleState = record.get('ScheduleState');

switch(scheduleState)
{
case "Defined":
definedCount++;
break;
case "In-Progress":
inProgressCount++;
break;
case "Completed":
completedCount++;
break;
case "Accepted":
acceptedCount++;
}
});

//Create a store containing the chart data
var scheduleStateStore = Ext.create('Ext.data.Store', {
fields: ['KanbanState', 'ObjectID_Count'],
data: {
rows: [
{ScheduleState: 'Defined', ObjectCount: definedCount},
{ScheduleState: 'InProgress', ObjectCount: inProgressCount},
{ScheduleState: 'Completed', ObjectCount: completedCount},
{ScheduleState: 'Accepted', ObjectCount: acceptedCount}
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'rows'
}
}
});

// Configure and Add the chart
this.add(
{
xtype: 'rallychart',
height: 400,
series: [
{
type: 'column',
dataIndex: 'ObjectCount',
name: 'Count',
visible: true
}
],
store: scheduleStateStore,
chartConfig: {
chart: {
},
title: {
text: 'User Story Schedule State Counts',
align: 'center'
},
xField : 'ScheduleState',
xAxis: [
{
categories: scheduleStateGroups,
title: {
text: 'ScheduleState'
}
}
],
yAxis: {
title: {
text: 'Count'
}
},
plotOptions : {
column: {
color: '#F00'
},
series : {
animation : {
duration : 2000,
easing : 'swing'
}
}
}
}
}
);
}
});
Rally.launchApp('CustomApp', {
name: 'ChartExample'
});
});
</script>

<style type="text/css">
.app {
/* Add app styles here */
}
</style>
</head>
<body></body>
</html>

关于javascript - 向图表添加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13843692/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com