我正在使用 AngularJS 构建一个 Ionic 应用程序。在这个应用程序中,我想要一个数据折线图。昨天我问了一个关于这个的问题 ( Angular-Chart not rendering anything ) 已经回答了,但现在有一个新问题。
有时图表立即可见,但当我在横向/纵向之间旋转屏幕时,它每次旋转都会变大。 有时,在您旋转屏幕几次之前,图表根本不可见(图例除外)。
当我用我的 iPhone 上的网络检查器检查它时,我发现高度的 HTML 属性每次都变大。 CSS-height 样式也是如此。
网络检查器中的 HTML 最初看起来像这样:(这是当图表在非事件选项卡上时)
<div ng-show="graph.visible && finishedLoading" class="ng-hide" style="">
<div class="chart-container"><canvas class="chart chart-line" data="graph.data" labels="graph.labels" options="graph.options" series="graph.series" colours="graph.colours" getcolour="graph.getColour" click="graph.click" hover="graph.hover" legend="graph.legend" width="576" height="424" style="width: 288px; height: 212px;">
</canvas><chart-legend><ul class="line-legend"><li><span style="background-color:rgba(70,191,189,1)"></span>Waarde</li><li><span style="background-color:rgba(247,70,74,1)"></span>Bovengrens</li><li><span style="background-color:rgba(253,180,92,1)"></span>Ondergrens</li></ul></chart-legend></div>
</div>
激活该选项卡后,其 HTML 如下所示:
<div ng-show="graph.visible && finishedLoading" class="" style="">
<div class="chart-container"><canvas class="chart chart-line" data="graph.data" labels="graph.labels" options="graph.options" series="graph.series" colours="graph.colours" getcolour="graph.getColour" click="graph.click" hover="graph.hover" legend="graph.legend" width="576" height="424" style="width: 288px; height: 212px;">
</canvas><chart-legend><ul class="line-legend"><li><span style="background-color:rgba(70,191,189,1)"></span>Waarde</li><li><span style="background-color:rgba(247,70,74,1)"></span>Bovengrens</li><li><span style="background-color:rgba(253,180,92,1)"></span>Ondergrens</li></ul></chart-legend></div>
</div>
这次图表立即可见,但情况并非总是如此。我认为这与网络检查员有关。当我没有打开网络检查器时,最初只有图例可见。
旋转到横向并返回纵向四次后,HTML 如下所示:
<div ng-show="graph.visible && finishedLoading" class="" style="">
<div class="chart-container"><canvas class="chart chart-line" data="graph.data" labels="graph.labels" options="graph.options" series="graph.series" colours="graph.colours" getcolour="graph.getColour" click="graph.click" hover="graph.hover" legend="graph.legend" width="576" height="816" style="width: 288px; height: 408px;">
</canvas><chart-legend><ul class="line-legend"><li><span style="background-color:rgba(70,191,189,1)"></span>Waarde</li><li><span style="background-color:rgba(247,70,74,1)"></span>Bovengrens</li><li><span style="background-color:rgba(253,180,92,1)"></span>Ondergrens</li></ul></chart-legend></div>
</div>
如您所见,每次旋转高度都会变大。
HTML 文件如下所示:
<div ng-show="graph.visible && finishedLoading">
<canvas
class="chart chart-line"
data="graph.data"
labels="graph.labels"
options="graph.options"
series="graph.series"
colours="graph.colours"
getColour="graph.getColour"
click="graph.click"
hover="graph.hover"
legend="graph.legend">
</canvas>
</div>
$scope.graph 看起来像这样:
$scope.graph = {
data: [
[], // value
[], // upper value
[] // lower value
],
labels: [],
options: {
animation: false,
pointDotRadius : 2,
datasetFill : false,
responsive: true,
maintainAspectRatio: false,
scaleGridLineColor : 'rgba(0, 0, 0, .1)',
showTooltips: false
},
series: ['Waarde', 'Bovengrens', 'Ondergrens'],
colours: ['#46BFBD', '#F7464A', '#FDB45C'],
// getColour:
// click:
// hover:
legend: true,
visible: false
}
这些值在这里设置:
function loadGraphData() {
$scope.graph.data = [
[], // value
[], // upper value
[] // lower value
];
$scope.graph.labels = [];
for (var key in $scope.results) {
var result = $scope.results[key];
$scope.graph.data[0].push(result.value);
$scope.graph.data[1].push(result.high);
$scope.graph.data[2].push(result.low);
$scope.graph.labels.push($filter('date')(result.date, 'dd MMM HH:mm'));
}
};
一旦请求完成加载,即在带有图表的选项卡可见之前调用。
我为canvas申请的CSS是:
canvas {
width: 100%!important;
height: 100%!important;
}
我希望问题很清楚并且有人可以帮助我。我已经尝试了我能想到的一切。如果需要更多信息,请告诉我!
编辑//需要注意的一点:当我将图表放在第一个选项卡(最初处于事件状态)时,图表立即可见,但它有同样奇怪的问题,即在调整浏览器窗口大小时变大..
最佳答案
尝试添加人行横道插件后。希望它有效。插件文档 here
关于javascript - 奇怪的 Angular-ChartJS 问题,无法在 Ionic App 中正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29819173/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search