Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>AngularJS Graph with animated SVG line</h1>

<div ng-app="graphApp">
  <div ng-controller="graphController as graph">
  
  <div class="graph" style="width:{{width}}px; height:{{height}}px;" >
    
    <div class="y" style="width:{{height}}px;">{{yAxis}}</div>
    
    <div class="x">{{xAxis}}</div>
    <svg height="{{height}}" width="100%">
      <line class="line{{$index}}" ng-repeat="point in points" x1="{{width / maxX * $index }}" y1="{{points[$index - 1].yValue / maxY * height}}" x2="{{width / maxX * ($index + 1)}}" y2="{{point.yValue / maxY * height}}" />
    </svg>
    <div class="dot dot{{$index}}" ng-repeat="point in points" style="bottom:calc({{point.yValue}}/{{maxY}}*{{height}}px - 5px); left:calc({{point.xValue}}/{{maxX}}*{{width}}px - 5px);" data-title="{{point.label}}: {{point.yValue}}"></div>
    
  </div>
</div>
</div>

<p>It always struck me that AngularJS could be used as a nice simple tool for visualising data.</p>

<p>Here I use ng-repeat and data binding for inline styling and controlling SVG</p>    


              
            
!

CSS

              
                * {box-sizing:border-box;}

h1 {
  color: #D07371;
}

body {
  font-size:1.1em;
  text-align:center;
  background:#F4F0DC;
  color:#444;
}

p {
  width:60%;
  margin:20px auto;
}

.graph {
  position:relative;
  margin:50px auto;
  background:#D9F2E6; 
}

svg {
  transform: rotateX(180deg);
  position:relative;
}

.y {
  font-weight:bold;
  border-bottom:1px solid #71CBD0;
  position:absolute;
  text-align:center;
  padding: 10px;
  transform: rotate(-90deg);
  transform-origin: bottom left;
  bottom:0;
  color: #D07371;
}

.x {
  font-weight:bold;
  border-top:1px solid #71CBD0;
  position:absolute;
  width: 100%;
  text-align:center;
  padding: 10px;
  top:100%;
  color:#D07371;
}

.dot {
  border-radius:50%;
  width:0px;
  height:0px;
  position:absolute;
  background:#71CBD0;
  cursor: pointer;
  animation: dots 100ms linear forwards;
  &:after {
    content:attr(data-title);
    display:inline-block;
    white-space: nowrap;
    overflow:hidden;
    background:#D07371;
    color:white;
    position:absolute;
    padding:10px;
    left:150%;
    top:-15px;
    width:0;
    opacity:0;
    border-radius:3px;
    font-weight:700;
  }
  
  &:hover {
    background:#D07371; 
     
    &:after {
      width:auto;
      opacity:1;
      z-index:9999;
    }
  }
}

line {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  stroke:#D07371;
  stroke-width:2;
  animation: dash 500ms linear forwards;
}

.lines(11);

.lines(@n, @i: 0, @a :0) when (@i =< @n) {
  .line@{i} {
    animation-delay:(@a+1000)*1ms;
  }
  .dot@{i} {
    animation-delay:(@a+1150)*1ms;
  }
  .lines(@n, (@i + 1), (@a + 150));
}

@keyframes dash {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes dots {  
  0% {
    width:0px;
    height:0px;
  }
  
  50% {
    width:10px;
    height:10px;
  }
  
  75% {
    width:15px;
    height:15px;
  }
  
  100% {
    width:10px;
    height:10px;
  }
}
              
            
!

JS

              
                (function(){

  var app = angular.module('graphApp',[]);
  
  app.controller('graphController', function($scope){
    
    // Options
    
    $scope.width = 600;
    $scope.height = 350;
    $scope.yAxis = 'Sales';
    $scope.xAxis = '2014';
    
    // Data 

    $scope.points = [
      {
      label: 'January',
      xValue: 1,
      yValue: 36
      },
      {
      label: 'February',
      xValue: 2,
      yValue: 54
      },
      {
      label: 'March',
      xValue: 3,
      yValue: 62
      },
      {
      label: 'April',
      xValue: 4,
      yValue: 82
      },
      {
      label: 'May',
      xValue: 5,
      yValue: 96
      },
      {
      label: 'June',
      xValue: 6,
      yValue: 104
      },
      {
      label: 'July',
      xValue: 7,
      yValue: 122
      },
      {
      label: 'August',
      xValue: 8,
      yValue: 152
      },
      {
      label: 'September',
      xValue: 9,
      yValue: 176
      },
      {
      label: 'October',
      xValue: 10,
      yValue: 180
      },
      {
      label: 'November',
      xValue: 11,
      yValue: 252
      },
      {
      label: 'December',
      xValue: 12,
      yValue: 342
      }
    ];
    
    // Find Maximum X & Y Axis Values - this is used to position the points as a percentage of the maximum
    $scope.maxY = 0;
    $scope.maxX = 0;
    
    var arrLength = $scope.points.length;
    for (var i = 0; i < arrLength; i++) {
        // Find Maximum X Axis Value
      	if ($scope.points[i].yValue > $scope.maxY)
        $scope.maxY = $scope.points[i].yValue;
      	// Find Maximum Y Axis Value
      	if ($scope.points[i].xValue > $scope.maxX)
        $scope.maxX = $scope.points[i].xValue;
    }
   
  // End Controller  
	});

})();
              
            
!
999px

Console