Ichart.js The implementation code _javascript technique of drawing dashed line and average dotted-line effect

Source: Internet
Author: User
Tags dashed line ichart

ichart.js Implementation code to draw a dashed line, average dotted line effect

var data=new Array (); 
          Data[0] = {labels: ["Unit One", "Unit Two", "Unit three", "Unit Four", "Unit V"], datasets: [{name: ' Excellent rate ', Color: ' #1dbcfe ', line_width:4, Value: [80,75,92,62,0]}]} Da 
          Ta[1] = {labels: ["Unit One", "Unit Two", "Unit three", "Unit Four", "Unit V"], datasets: [{name: ' Excellent rate ', Color: ' #1dbcfe ', line_width:4, Value: [50,11,62,77,90]}]} Dat 
          A[2] = {labels: ["Unit One", "Unit Two", "Unit three", "Unit Four", "Unit V"], datasets: [{name: ' Excellent rate ', 
     
    Color: ' #1dbcfe ', line_width:4, Value: [80,51,32,44,80]}]} 
    var _bodywidth=$ (' body '). Width ()-16; 
      $ ('. Item '). Each (the function (i) {var _id=$ (this). Find ('. Canvas-wrap '). attr (' id '); var chart = new Ichart.linebasic2d ({render: _id, Data:data[i].datasets, ALIGN: ' Center ', border:0, Width: _bodywidth*2, Height: _bodywidth*1.2, Background_colo R: ' #fafafa ', animation:true,//turn on transition animation animation_duration:600,//600ms complete animation sub_option 
          : {smooth:true, Hollow:false, Hollow_inside:false, Point_size:16, 
            Listeners: {parsetext:function (R, t) {return t+ '% '; }, Label:{fontsize:24,color: ' #333 '}, coordinate:{width:_bodywidth 
          *1.6, valid_width:_bodywidth*1.4, height:_bodywidth*1.6*.5, striped_factor:0.18, axis:{color: ' #aaa ', width:[0,0,8,0]}, scale:[{Positi On: ' Left ', start_scale:0, end_scale:100, scale_space:20, Scale_si 
   Ze:2, Scale_enable:false,          Label: {color: ' #999 ', fontsize:24}, Scale_color: ' #999 '},{position: ' Botto M ', Label: {color: ' #999 ', fontsize:24}, Scale_enable:false, Labels:data[i].lab 
      ELS}]}); 
       /** * Custom component, draw the average line. 
             /Chart.plugin (new Ichart.custom ({drawfn:function () {/** *) calculates the average height (coordinate y value) 
            * * var _total=0; 
            $.each (Data[i].datasets[0].value,function (i,val) {_total+=val; 
            }); 
              The var avg = _total/data[i].datasets[0].value.length,//calculates the average score in this can be COO = chart.getcoordinate (), x = Coo.get (' Originx '), W = coo.width, S = Coo.getscale (' left '), H = coo.he 
            ight, H = (avg-s.start) * h/s.distance, y = chart.y + h-h; For (xi=x;xi<= (x+w); xi=xi+32) {chart.target.line (xi,y,xi+16,y,2, ' #fe941c '); } chart.target.textAlign (' Start '). Textbaseline (' Middle '). Textfont (' 20px Verda 
          Na '). Filltext (' average defeating rate ' +avg+ '% ', x+w-100,y-20,false, ' #fe941c '); 
      } 
      })); 
    Chart.draw (); });

The above code is a JS example of drawing multiple line charts, and a way to draw an average dotted line within each line chart.

Ichart.js is a very good icon to draw JS, the disadvantage is that the mobile end needs to set twice times the size, and then manually reduce the CSS and JS to the normal range to keep it on the screen to maintain high-definition.

The official website has an example of an average line, but there are no dotted lines, and in general, in order not to confuse, the average line is drawn with a dash. Here I'm just looping through the N-end line, which is a flexible method. If there is a better way please leave a message oh thank you.

The above ichart.js draw dotted line, the average dotted line effect of the implementation code is small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.