得到tickpositions highcharts

时间:2016-03-29 15:16:30

标签: highcharts freemarker scatter-plot

我有一个highcharts散点图,我试图在freemarker模板中获取x和y tickPositions,特别是第一个和最后一个。比如说我会在xy轴和[30,40](右上角)交叉点的相对边交叉处得到[-10,-10](左下角)的东西,其中xAxis是[-10,0,10,20,30]和yAxis刻度是[-10,0,10,20,30,40]

我想要这些点,这样我就可以在从底部下角到右上角的散点图上绘制一条对角线。系列应如下所示:

Get-ChildItem C:\files\ |Select-String -Pattern '^(?=.*\d)\w{8}$'
Get-ChildItem C:\files\ |Select-String -Pattern '\b(?=.*\d)\w{8}\b'

目前的问题是我无法获得[-10,-10],[30,40]数据点。甚至可能是我想知道的。非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

您在轴上有getExtremes()功能。 例如:

var extremes = $('#container').highcharts().yAxis[0].getExtremes();

以下是doc,此处是demo fiddle

这是你想要达到的目标吗?

修改

在你的小提琴例子之后,我更了解你的需要。 这是updated fiddle

  var chart = $('#container').highcharts();
  var extremeY = chart.yAxis[0].getExtremes();
  var extremeX = chart.xAxis[0].getExtremes();

  var lineSeries = {
      type: 'line',
      data: [
        [extremeX.min, extremeY.min],
        [extremeX.max, extremeY.max]
      ],
      lineWidth: 0.5,
      lineColor: 'rgb(0,0,0)',
      marker: {
        enabled: false
      }
    };

  chart.addSeries(lineSeries);

我创建了一个具有线系列属性的对象。使用min返回的对象中的maxdataMin(不是dataMaxgetExtremes())属性,您可以获得所需的结果。

修改2

您可以将此代码放入图表的load事件中。这是在图表完成加载后调用的回调。在这里,您可以使用this来引用图表:

 $('#container').highcharts({
    chart: {
      events: {
        load: function() {
          var extremeY = this.yAxis[0].getExtremes();
          var extremeX = this.xAxis[0].getExtremes();

          var lineSeries = {
            type: 'line',
            data: [
              [extremeX.min, extremeY.min],
              [extremeX.max, extremeY.max]
            ],
            lineWidth: 0.5,
            lineColor: 'rgb(0,0,0)',
            marker: {
              enabled: false
            }
          };

          this.addSeries(lineSeries);
        }
      },
      //...
});

以下是new updated fiddle

答案 1 :(得分:0)

由于您只需要一个对角线路径,因此您可以使用renderer

添加它

示例:http://jsfiddle.net/cr7gq4st/

function diagonal() {
    var chart = this,
            ren = chart.renderer,
        diag = chart.diag,
        attrs = {
            'stroke-width': 0.5,
          stroke: '#000',
          zIndex: 1
        },
        topR = {
            x: chart.plotLeft + chart.plotWidth,
          y: chart.plotTop
        },
        bottomL = {
            x: chart.plotLeft,
          y: chart.plotTop + chart.plotHeight
        },
        d = 'M ' + bottomL.x + ' ' + bottomL.y + ' L ' + topR.x + ' ' + topR.y;
    if( !diag ) { //if doesn't exist, then create
        chart.diag = ren.path().attr(attrs).add();
    }
    chart.diag.attr({d:d});
}