行名称重叠

时间:2013-04-24 06:41:36

标签: highcharts highstock

我创建了散点图http://jsfiddle.net/ashwinp/4aDQ2/1/

这里的行名称是相互重叠的?并且从行名称的中间开始绘制点。为什么我们不能从行名称的开头开始?

我可以知道如何解决这个问题吗?

这是代码

var InfluenceCnt=0;
var QResiduals=[];
var XLables=[];
var HottelingT2=[];
var EllipseChartData;
var EllipseShift;
QResiduals.push('0.5356899');
QResiduals.push('0.3356899');
QResiduals.push('0.6356899');
QResiduals.push('0.2356899');
QResiduals.push('0.8356899');
QResiduals.push('0.2356899');
QResiduals.push('0.4356899');
QResiduals.push('0.4356899');
QResiduals.push('0.4356899');
QResiduals.push('0.2356899');
QResiduals.push('0.2356899');
QResiduals.push('0.5356899');
QResiduals.push('0.8356899');
QResiduals.push('0.9356899');
QResiduals.push('0.5356899');
QResiduals.push('0.7356899');
QResiduals.push('0.2356899');
QResiduals.push('0.1356899');
QResiduals.push('0.0356899');
QResiduals.push('0.5356899');
QResiduals.push('0.8356899');
QResiduals.push('0.7356899');

HottelingT2.push('0.1')
HottelingT2.push('0.2');
HottelingT2.push('0.3');
HottelingT2.push('0.4');
HottelingT2.push('0.5');
HottelingT2.push('0.6');
HottelingT2.push('0.4')
HottelingT2.push('0.5');
HottelingT2.push('0.3');
HottelingT2.push('0.2');
HottelingT2.push('0.6');
HottelingT2.push('0.7');
HottelingT2.push('0.8')
HottelingT2.push('0.9');
HottelingT2.push('0.2');
HottelingT2.push('0.3');
HottelingT2.push('0.5');
HottelingT2.push('0.5');
HottelingT2.push('0.7')
HottelingT2.push('0.8');
HottelingT2.push('0.9');
HottelingT2.push('0.4');
HottelingT2.push('0.5');
HottelingT2.push('0.6');

XLables.push('abc')
XLables.push('bdef');
XLables.push('ceff');
XLables.push('ddds');
XLables.push('edf');
XLables.push('fdf');
XLables.push('abc')
XLables.push('bdef');
XLables.push('ceff');
XLables.push('dddsert');
XLables.push('edf');
XLables.push('fdf');
XLables.push('abcert')
XLables.push('bdefert');
XLables.push('ceffert');
XLables.push('retret');
XLables.push('edfert');
XLables.push('fdfret');
XLables.push('bdefert');
XLables.push('ceff');
XLables.push('ddds');
XLables.push('edf');
XLables.push('fdf');

$(function () {
             $(document).ready(function () {        
                 Highcharts.setOptions({
                     global: {
                         useUTC: false
                     }
                 });
  // Ellipse Plot
          EllipseChartData = new Highcharts.Chart({
                     chart: {
                         renderTo: 'EllipseContainer',
                         type: 'scatter',
                         marginRight: 10,
                         zoomType: 'xy',
                         events: {
                             load: function () {                             

                                 // set up the updating of the chart each second
                                EllipseSeries = this.series[0];                                
                                  setInterval(function () {                                    
                                    EllipseShift = EllipseSeries.data.length > 20;                         

                                    if (!isNaN(QResiduals[InfluenceCnt]) &&  $.isNumeric(QResiduals[InfluenceCnt]) && typeof (QResiduals[InfluenceCnt]) != "undefined") {  //alert(QResiduals[InfluenceCnt]); 
                                         var x = HottelingT2[InfluenceCnt], // current time 
                                             y = parseFloat(QResiduals[InfluenceCnt]);    
                                         InfluenceCnt++;                                                                          
                                         EllipseSeries.addPoint([x,y], true, EllipseShift);                                         
                                       }                                     
                                 }, 1000);
                             }
                         }
                     },
                     title: {
                         text: 'Ellipse Plot'
                     },
                     xAxis: {
                         title: {
                             text: 'Sample'
                         },
                         categories:XLables,
                         plotLines: [{                           
                            value:2.5,
                            color: 'red',
                            dashStyle: 'shortdash',
                            width: 2,
                            label: {
                                text: ''
                            }
                         }]
                     },
                     yAxis: {
                         title: {
                             text: ''
                         },
                         plotLines: [{                            
                            value: 0.4,
                            color: 'red',
                            dashStyle: 'shortdash',
                            width: 2,
                            label: {
                                text: ''
                            }
                         }]
                     },
                     tooltip: {
                         formatter: function () {
                             return '<b>' + this.series.name + '</b><br/>X: ' +
                        this.x + '<br/> Y: ' +
                        Highcharts.numberFormat(this.y, 2);
                         }
                     },
                     legend: {
                         enabled: false
                     },
                     exporting: {
                         enabled: true
                     },
                    series: [{
                        name: 'Ellipse Plot',
                        data: []
                    }]
                 });


             });

         });

提前致谢。

2 个答案:

答案 0 :(得分:0)

您的宽度有限,因此标签重叠,因为“没有空格”以包含“margin / padding”。你可以尝试使用HTML作为true:http://api.highcharts.com/highcharts#xAxis.labels.useHTML然后使用formatter()http://api.highcharts.com/highcharts#xAxis.labels.formatter,即

return '<div class="ownlabel">'+this.value+'</div>';

然后使用您自己的css样式定义“ownlabel”。

答案 1 :(得分:0)

问题是您正在使用类别,因此Highcharts不会阻止任何重叠。我建议在格式化程序中使用标准xAxis,看看:http://jsfiddle.net/TEDBG/

                 xAxis: {
                     allowDecimals: false,
                     labels: {
                          formatter: function() {
                              return XLables[this.value];
                          }
                     }       
                 }