javascript - Levels is overlapping in angular-chart.js -


i using angular-chart.js

<div class="container" ng-controller="linectrl">      <canvas id="bar" class="chart chart-bar" data="barchartdata" options="options" series="linechartseries"             colours="colours" legend="true" labels="barchartlabel"></canvas> </div> 

css chart is

.chart #bar {   width: 100%!important;  height: 300px; } 

but chart showing overlapping labels like

enter image description here

that's because chart.js shows x axis labels , doesn't drop them if overlap. there feature request out there https://github.com/nnnick/chart.js/pull/897 - still open.

there separate branch - https://github.com/nnnick/chart.js/pull/521 solves issue. but, hasn't been integrated main branch yet , might want read full thread before opting this.


there workaround however. can opt set except every nth label when pass in labels array, this

labels: ["jan 1", "jan 2",... , lots of days ....].map(function (e, index) {      return index % 5 ? "" : e; }) 

adjust value 5 needed. best way adjust based on size of array x number of points or less if number of points crosses threshold. e.g. if want no more 10 points, replace 5 size of array / 10 if size of array > 200 or @ whichever point overlaps start. make sure don't end less markers :-). instance, if pick 30 instead of 200 threshold, there times when have 3 markers 30+ data points. or can choose more creative mapping function (for example, make sure have label @ end of scale, etc.)

here example chart.js. same logic work angular-chart.js well.

var mylabels = [] var myvalues = [] (var = 0; < 1000; i++) {     mylabels.push("label" + i);     myvalues.push(math.random() * 1000) }  var data1 = {     labels: mylabels,     datasets: [{         label: "my dataset",         fillcolor: "rgba(244, 6, 6, 1)",         data: myvalues     }] };  var ctx = document.getelementbyid("chart1").getcontext("2d"); window.weekschart = new chart(ctx).bar(data1, {     barshowstroke : false });   var data2 = {     labels: mylabels.map(function (e, index) {          return index % 30 ? "" : e;     }),     datasets: [{         label: "my dataset",         fillcolor: "rgba(244, 6, 6, 1)",         data: myvalues     }] };  var ctx = document.getelementbyid("chart2").getcontext("2d"); window.weekschart = new chart(ctx).bar(data2, {     barshowstroke : false }); 

with html

<canvas id="chart1" width="651" height="335"></canvas> <canvas id="chart2" width="651" height="335"></canvas> 

and here corresponding fiddle - http://jsfiddle.net/2kvwndtq/

the downside if want tooltips have override tooltip function show spaces corresponding label , not blank.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -