0
Reply

Writing command different so it would be less typing.

Cassie Mod

Cassie Mod

Jan 28 2016 9:37 AM
354
HI,
 
 
Ive got the following script ( wich works perfectly), but i was wundering is it possible to rewrite "data" so it would use less code ( i'm new to asp.net so it would probably be possible ).
 
questions:
1: how to rewrite data so it would use less code
2. What linQ command  should i  use to get an array of all CollectorID's of @Model.CollectorStatus So i could replace that for categories in the script. 
 
other example: @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID==1) // now i need a code to get the array.
 
Code:
 
 
  1. <script type="text/javascript">  
  2.     $(document).ready(function () {  
  3.   
  4.  $("#collectorscompleted").kendoChart({  
  5.         legend: {  
  6.             visible: false  
  7.         },  
  8.         seriesDefaults: {  
  9.             type: "column"  
  10.         },  
  11.         series: [{  
  12.             name: "Completed",  
  13.             data: [@Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID==1), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 2), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 3), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 4),  
  14.                    @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 5), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 6), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 7), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 8),  
  15.                    @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 9), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 10), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 13), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 14),  
  16.                    @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 15), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 16), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 17), @Model.CollectorStatus.Count(c => c.BatchCompleted == true && c.CollectorID == 18)]  
  17.                    // This needs to be in less code
  18.         }, {  
  19.             name: "Failed",  
  20.             data: [@Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID==1), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 2), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 3), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 4),  
  21.                    @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 5), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 6), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 7), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 8),  
  22.                    @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 9), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 10), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 13), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 14),  
  23.                    @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 15), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 16), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 17), @Model.CollectorStatus.Count(c => !c.BatchCompleted == true && c.CollectorID == 18)]  
  24.                    // this needs to be in less code 
  25.         }],  
  26.         valueAxis: {  
  27.             labels: {  
  28.                 visible: false  
  29.             },  
  30.             line: {  
  31.                 visible: false  
  32.             },  
  33.             majorGridLines: {  
  34.                 visible: false  
  35.             }  
  36.         },  
  37.         categoryAxis: {  
  38.             categories: [1,2,3,4,5,6,7,8,9,10,13,14,15,16,17,18], 
  39.              // needs to be replaces
  40.             line: {  
  41.                 visible: false  
  42.             },  
  43.             majorGridLines: {  
  44.                 visible: false  
  45.             }  
  46.         },  
  47.         chartArea: {  
  48.             background: "none"  
  49.         },  
  50.         tooltip: {  
  51.             visible: true,  
  52.             format: "{0}",  
  53.             template"#= series.name #: #= value #"  
  54.         }  
  55.     });  
  56. });  
  57.   
  58. </script>