1+ // Visualization Script
2+ // Visualization Script
3+ var template = `
4+ < canvas id ="myChart " height ="100 "> </ canvas >
5+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js "> </ script >
6+ < script >
7+ var ctx = document . getElementById ( "myChart" ) ;
8+ var myChart = new Chart ( ctx , {
9+ type : "bar" ,
10+ data : {
11+ labels : [ ] ,
12+ datasets : [
13+ {
14+ label : 'Total Codewords' ,
15+ data : [ ] ,
16+ backgroundColor : 'rgba(54, 162, 235, 0.6)' ,
17+ borderColor : 'rgba(54, 162, 235, 1)' ,
18+ borderWidth : 1
19+ } ,
20+ {
21+ label : 'Total Errors' ,
22+ data : [ ] ,
23+ backgroundColor : 'rgba(255, 99, 132, 0.6)' ,
24+ borderColor : 'rgba(255, 99, 132, 1)' ,
25+ borderWidth : 1
26+ }
27+ ]
28+ } ,
29+ options : {
30+ legend : { display : true } ,
31+ title : {
32+ display : true ,
33+ text : 'Codeword Error Rate by Channel ID'
34+ } ,
35+ scales : {
36+ xAxes : [ {
37+ display : true ,
38+ scaleLabel : {
39+ display : true ,
40+ labelString : 'Channel ID'
41+ }
42+ } ] ,
43+ yAxes : [ {
44+ display : true ,
45+ scaleLabel : {
46+ display : true ,
47+ labelString : 'Count'
48+ } ,
49+ ticks : {
50+ beginAtZero : true
51+ }
52+ } ]
53+ }
54+ }
55+ } ) ;
56+
57+ pm . getData ( function ( err , value ) {
58+ myChart . data . labels = value . channelIds ;
59+ myChart . data . datasets [ 0 ] . data = value . totalCodewords ;
60+ myChart . data . datasets [ 1 ] . data = value . totalErrors ;
61+ myChart . update ( ) ;
62+ } ) ;
63+
64+ </ script > `;
65+
66+ function createPayload() {
67+ var responseData = pm.response.json();
68+ var results = responseData.results || [];
69+
70+ var channelIds = [];
71+ var totalCodewords = [];
72+ var totalErrors = [];
73+
74+ for (var i = 0; i < results .length; i++) {
75+ channelIds.push(results[i].channel_id.toString());
76+ totalCodewords.push(results[i].codeword_totals.total_codewords);
77+ totalErrors.push(results[i].codeword_totals.total_errors);
78+ }
79+
80+ return {
81+ channelIds: channelIds,
82+ totalCodewords: totalCodewords,
83+ totalErrors: totalErrors
84+ };
85+ }
86+
87+ pm.visualizer.set(template, createPayload());
0 commit comments