0

这是实时散点图的简化版本http://jsfiddle.net/ashwinp/z6QXW/8/

现在我在 x 轴上得到 0 1 2 等。我希望 x 轴上的用户定义名称。X 轴标签应该从 XLables 数组中提取。

我在这里添加了来自 jsfiddle 的相同代码

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

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

XLables.push('a')
XLables.push('b');
XLables.push('c');
XLables.push('d');
XLables.push('e');
XLables.push('f');

 $(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'
                     },
                     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: ' +
                    Highcharts.numberFormat(this.x, 2) + '<br/> Y: ' +
                    Highcharts.numberFormat(this.y, 2);
                     }
                 },
                 legend: {
                     enabled: false
                 },
                 exporting: {
                     enabled: true
                 },
                series: [{
                    name: 'Ellipse Plot',
                    data: []
                }]
             });


         });

     });
4

2 回答 2

1

您需要的选项是 xAxis 上的“类别”。尝试这个:

xAxis: {
      title: {
           text: 'Sample'
      },
      categories:XLables,

http://jsfiddle.net/euVvy/

要修复工具提示,您只需要参考“this.x”,它将返回类别名称:

                tooltip: {
                     formatter: function () {
                         return '<b>' + this.series.name + '</b><br/>X: ' +
                    this.x + '<br/> Y: ' +
                    Highcharts.numberFormat(this.y, 2);
                     }
                 },

http://jsfiddle.net/4aDQ2/

于 2013-04-23T07:51:02.520 回答
0

您可以使用类别或标签格式化程序,它允许定义“显示的标签http://api.highcharts.com/highstock#xAxis.labels.formatter

于 2013-04-23T08:00:16.930 回答