Angular Chart.js not displaying Chart (Legend is Displaying) - angularjs
I am using the Angular-chart.js package:
http://jtblin.github.io/angular-chart.js/
When I load the page, the legend at the bottom of the page shows, but the chart itself is not displayed.
I added divs to verify that the data is actually populated. Here is the code that I have so far:
<div>
<span>
vm.bvpsData -
</span>
{{vm.bvpsData | json}}
</div>
<div>
<span>
vm.bvpsLabels -
</span>{{vm.bvpsLabels | json}}
</div>
<div>
<span>
vm.bvpsSeries -
</span>{{vm.bvpsSeries | json}}
</div>
<canvas id="bvpsChart" class="chart chart-line" data-data="vm.bvpsData"
data-labels="vm.bvpsLabels" data-legend="true" data-series="vm.bvpsSeries">
</canvas>
When I run the page and look at the code, this is what is rendered in the html:
<div class="ng-binding"><span>vm.bvpsData -</span>[
[
"6.88",
"6.95",
"4.31",
"4.33",
"4.45",
"4.49",
"4.16",
"4.04",
"3.92",
"3.61",
"3.68",
"3.55",
"3.21",
"3.38",
"3.62",
"3.98",
"3.86",
"3.66",
"3.87",
"4.15",
"4.41",
"4.59",
"4.95",
"5.15",
"5.22",
"5.40",
"5.66",
"6.28",
"6.68",
"7.00",
"7.57",
"8.08",
"7.79",
"8.10",
"8.59",
"9.10",
"9.33",
"9.68",
"10.14",
"10.45",
"10.74",
"10.80",
"11.07",
"10.94"
]
]</div>
<div class="ng-binding"><span>vm.bvpsLabels -</span>[
"06/2004",
"09/2004",
"12/2004",
"03/2005",
"06/2005",
"09/2005",
"12/2005",
"03/2006",
"06/2006",
"09/2006",
"12/2006",
"03/2007",
"06/2007",
"09/2007",
"12/2007",
"03/2008",
"06/2008",
"09/2008",
"12/2008",
"03/2009",
"06/2009",
"09/2009",
"12/2009",
"03/2010",
"06/2010",
"09/2010",
"12/2010",
"03/2011",
"06/2011",
"09/2011",
"12/2011",
"03/2012",
"06/2012",
"09/2012",
"12/2012",
"03/2013",
"06/2013",
"09/2013",
"12/2013",
"03/2014",
"06/2014",
"09/2014",
"12/2014",
"03/2015"
]</div>
<div class="ng-binding"><span>vm.bvpsSeries -</span>[
"Book Value Per Share"
]</div>
<div class="chart-container">
<canvas id="bvpsChart" class="chart chart-line ng-isolate-scope" data-data="vm.bvpsData" data-labels="vm.bvpsLabels" data-legend="true" data-series="vm.bvpsSeries" width="929" height="0" style="width: 929px; height: 0px;"></canvas>
<chart-legend>
<ul class="line-legend">
<li><span style="background-color:rgba(151,187,205,1)"></span>Book Value Per Share</li>
</ul>
</chart-legend>
</div>
What am I doing wrong? Why is the chart not displaying?
I fixed the problem. I had the chart canvas in a div with an ng-show and kept it hidden until a stock was selected.
I changed it to an ng-if and everything worked perfect after that.
Related
AngularJS: Swiper.js not showing background images
I´m trying to integrate swiper.js in my angularJs web app displaying background images. The library is working but the images are not properly displayed. Please see this plunker that is working exactly like my app. http://plnkr.co/edit/ISdEZn?p=preview Below the most relevant part: <!-- Slider main container --> <div class="swiper-container" swiper> <!-- Additional required wrapper --> <div class="swiper-wrapper"> <!-- Slides --> <!--<div class="swiper-slide">Slide 1</div>--> <!--<div class="swiper-slide">Slide 2</div>--> <!--<div class="swiper-slide">Slide 3</div>--> <div class="swiper-slide" ng-repeat="boatPhoto in boatPhotos" is-loaded> <div style="margin:auto; background-image: url('//s3-eu-west-1.amazonaws.com/yanpy.dev/img/boats/13620/l/{{boatPhoto.name}}.{{boatPhoto.mime}}')"> </div> </div> </div> <!-- If we need pagination --> <div class="swiper-pagination"></div> <!-- If we need navigation buttons --> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> <!-- If we need scrollbar --> <div class="swiper-scrollbar"></div> </div>
You need to set width and height of the div. <div style="margin:auto;width:100%;height:100%; background-image: url('//s3-eu-west-1.amazonaws.com/yanpy.dev/img/boats/13620/l/{{boatPhoto.name}}.{{boatPhoto.mime}}')"> Hola </div> Updated plnkr demo
Angular Material swipe gesture works hardly
I am trying to add swipe functionality to a ng-repeated list of elements. However, the swiping works badly. Sometimes a swipe gestures (all on desktop) is recognized, but most of the times I'm click and swiping like a madman to achieve the expected result. I am using Material Angular. Code: <div ng-repeat="link in Links | filter: { category: 'quick' }"> <div ng-show="!link.show" md-swipe-left="link.show = true"> <div class="lv-item "> <span href="{{link.url}}" class="no-select" target="_blank" > <div class="lv-title" class="no-select">{{link.title}}</div> <small class="lv-small" class="no-select">{{link.description}}</small> </span> </div> </div> <div ng-show="link.show" md-swipe-right="link.show = false"> <div class="lv-item delete" > <button ng-click="deleteLink(link.id)">Verwijder</button> </div> </div> </div> On the Angular Material swipe docpage (https://material.angularjs.org/latest/demo/swipe) it seems easy and it works like a charm. However my implementation of the directive doesn't seem to work as it should. It rather lets me select the text inside the element than swiping. Also, I'd rather want the span to be a a href, but this only lets me drag the whole element out of space.
I believe that to assure a proper work of all material function you should use their containers and directives instead. So you should put all of that inside a md-content, and also use ng-ifs instead of ng-show on the swiped div. Which would result in something like that : <md-content> <div ng-repeat="link in Links | filter: { category: 'quick' }"> <div ng-if="!link.show" md-swipe-left="link.show = true"> <div class="lv-item "> <span href="{{link.url}}" class="no-select" target="_blank" > <div class="lv-title" class="no-select">{{link.title}}</div> <small class="lv-small" class="no-select">{{link.description}}</small> </span> </div> </div> <div ng-if="link.show" md-swipe-right="link.show = false"> <div class="lv-item delete" > <button ng-click="deleteLink(link.id)">Verwijder</button> </div> </div> </div> </md-content> I used this kind of code snippet on some md-sidenav and it works. By the way, if you're using chrome and use mobile view, the md-swipe-left is always triggered, doesn't matter if you swipe left, right, top or bottom. Hope this helps
angular-ui-grid nested in angular-ui-layout with 100% height
I am trying to show an angular-ui-grid in one of the containers/panes of an angular-ui-layout. The container should contain a toolbar at the top and the remaining space should be filled by either a chart or the corresponding data table which I tried to solve with a flexgrid and ng-include. My problem is that I don't get the ui-grid to initialize correctly when first shown and it does not fill the remaining space. Also it does not reliably resize when I resize the browser window, sometimes it does not grow accordingly, sometimes it does not shrink usually it's the scrollbars that are misaligned. I tried using handleWindowResize and ui-grid-auto-resize to no avail. The ui-layout is this: <div ui-layout="{flow : 'column'}" > <div ui-layout-container size="20%"> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> </div> <div ui-layout-container> <div style="height:100%;display:flex;flex-flow:column;padding:10px"> <form role="form" style="padding-bottom:10px"> <label>Toolbar</label> <button ng-click="showAnalysis1=true">Analysis 1</button> <button ng-click="showAnalysis1=false">Analysis 2</button> </form> <form role="form" style="padding-bottom:10px"> <label>Sub-Toolbar</label> <button ng-click="showChart=true">Show chart</button> <button ng-click="setShowChart(false)">Show table</button> </form> <div class="analysis-container" ng-show="showAnalysis1" ng-include="'analysis1.html'"> </div> <div class="analysis-container" ng-show="!showAnalysis1" ng-include="'analysis2.html'"> </div> </div> </div> </div> And the ui-grid is in an ng-include together with a dummy chart, f.e. <div ng-show="showChart"> Here goes the chart for analysis 1... </div> <div ng-show="!showChart" class="my-grid-container"> <div ui-grid="tableOptions" class="my-grid" ui-grid-auto-resize> </div> </div> The following plnkr shows this in context: http://plnkr.co/edit/gIynXCdy7Kkyl0iwiBid?p=preview To reproduce: press either Analysis1 or Analysis2 press Show table resize the browser window several times Please ignore the ui-layout splitter for now. At the moment I am only interested in resizing the browser window and having the ui-grid fill the remaining space at all.
I see you have correctly added the directive ui-grid-auto-resize, but you also must specify it as a module dependency for your module: angular.module('x', ['ui.layout', 'ui.grid','ui.grid.autoResize']) http://plnkr.co/edit/8VmwsvBGnbtZNsjDL95C?p=preview
ng-style not working inside nested ng-repeat
I've got the following markup: <li ng-repeat="month in months"> <!-- NOTE THAT THIS IS WORKING IN ALL BROWSERS --> <div class="cm-month-grid" ng-style="{width:{{month.pos.width}}+'px', left:{{month.pos.left}}+'px'}"> <div class="cm-month-title" title="{{month.date.format('DD.MM.YY')}} {{month.pos | json}}">{{month.date.format('MMM.YY')}}</div> <div class="cm-month-border"></div> </div> </li> that runs fine, but this is not: <li ng-repeat="unit in units | filter: filter.text"> <div class="cm-periods"> <!-- BUT THIS IS NOT WORKING... WHY.... <div ng-repeat="period in unit.periods" class="cm-period" ng-style="{width:{{period.pos.width}}+'px', left:{{period.pos.left}}+'px'}" data-period="{{.}}}"> <span >{{period.start.format('DD.MM.YY')}}</span> <div style="background: pink;" ng-style="{width:{{period.pos.width}}+'px', left:{{period.pos.left}}+'px'}">jalla</div> </div>--> <!-- WORKING IN CHROME ONLY --> <div ng-repeat="period in unit.periods" class="cm-period" style="width:{{period.pos.width}}px; left:{{period.pos.left}}px;" data-period="{{.}}}"> <span>{{period.start.format('DD.MM.YY')}}</span> </div> <!-- --> </div> </li> Full example could be seen here: http://plnkr.co/edit/aZsZEM?p=preview I know there are issues with style and IE, that's why I'm using the ngStyle, but it does not update it style (try clicking on the zoom in the full example in IE) Thanks for any help Larsi
You are using ng-style with double curly brackets. As far as I know that's not valid in an expression. Try this: <div ng-repeat="period in unit.periods" class="cm-period" ng-style="{'width':period.pos.width+'px', 'left':period.pos.left+'px'}" data-period="{{.}}}"> <span >{{period.start.format('DD.MM.YY')}}</span> <div style="background: pink;" ng-style="{'width':period.pos.width+'px', 'left':period.pos.left+'px'}">jalla</div> </div> </div> Hmm, still looks messy to me. But, HEY! it zooms! (in FF) Uh, forgot: Forked Plunk
Angular UI-Bootstrap 0.7.0 Collapse
I'm using the collapse feature of UI-Bootstrap (http://angular-ui.github.io/bootstrap/#/collapse) but when I use the collapse/toggle it loses the data and just returns "true". Here is a Plunker to show my issue, http://plnkr.co/edit/e689Wureay8AMZQ9IIno?p=preview A snippet from the code: <div ng-repeat="name in names | filter:radioModel:true"> <span ng-model="namesList" ng-click="name = !name">Toggle collapse {{name.firstName}}</span> <hr> <div ng-show="name"> <div class="well well-large">{{name}} -</div> </div>
That is because you are overwriting name in the ng-click here: ng-click="name = !name". That will make name true or false, depending on how many times ng-click was invoked. What you want is to toggle a property on the model to collapse/uncollapse the following detail: <div ng-repeat="name in names | filter:radioModel:true" > <!-- change the property name.collapsed --> <span ng-model="namesList" ng-click="name.collapsed = !name.collapsed">Toggle collapse {{name.firstName}}</span> <hr> <!-- use ng-hide to "collapse" --> <div ng-hide="!!name.collapsed"> <div class="well well-large">{{name}} -</div> </div> </div> Working demo: http://plnkr.co/edit/at7ceCYDXwWWlqUlKnkQ?p=preview