2017-04-13 1 views
1

X- 시리즈 하이 차트 그래프의 특정 데이터 포인트에 이미지를 추가 할 수 있습니까? 첫 번째 데이터 포인트하이 차트 데이터 포인트 이미지

/** 
* Highcharts X-range series plugin 
*/ 
(function (H) { 
    var defaultPlotOptions = H.getOptions().plotOptions, 
     columnType = H.seriesTypes.column, 
     each = H.each, 
     extendClass = H.extendClass, 
     pick = H.pick, 
     Point = H.Point, 
     Series = H.Series; 

defaultPlotOptions.xrange = H.merge(defaultPlotOptions.column, { 
    tooltip: { 
     pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>' 
    } 
}); 
H.seriesTypes.xrange = H.extendClass(columnType, { 
    pointClass: extendClass(Point, { 
     // Add x2 and yCategory to the available properties for tooltip formats 
     getLabelConfig: function() { 
      var cfg = Point.prototype.getLabelConfig.call(this); 

      cfg.x2 = this.x2; 
      cfg.yCategory = this.yCategory = this.series.yAxis.categories && this.series.yAxis.categories[this.y]; 
      return cfg; 
     } 
    }), 
    type: 'xrange', 
    forceDL: true, 
    parallelArrays: ['x', 'x2', 'y'], 
    requireSorting: false, 
    animate: H.seriesTypes.line.prototype.animate, 

    /** 
    * Borrow the column series metrics, but with swapped axes. This gives free access 
    * to features like groupPadding, grouping, pointWidth etc. 
    */ 
    getColumnMetrics: function() { 
     var metrics, 
      chart = this.chart; 

     function swapAxes() { 
      each(chart.series, function (s) { 
       var xAxis = s.xAxis; 
       s.xAxis = s.yAxis; 
       s.yAxis = xAxis; 
      }); 
     } 

     swapAxes(); 

     this.yAxis.closestPointRange = 1; 
     metrics = columnType.prototype.getColumnMetrics.call(this); 

     swapAxes(); 

     return metrics; 
    }, 

    /** 
    * Override cropData to show a point where x is outside visible range 
    * but x2 is outside. 
    */ 
    cropData: function (xData, yData, min, max) { 

     // Replace xData with x2Data to find the appropriate cropStart 
     var crop = Series.prototype.cropData.call(this, this.x2Data, yData, min, max); 

     // Re-insert the cropped xData 
     crop.xData = xData.slice(crop.start, crop.end); 

     return crop; 
    }, 

    translate: function() { 
     columnType.prototype.translate.apply(this, arguments); 
     var series = this, 
      xAxis = series.xAxis, 
      metrics = series.columnMetrics, 
      minPointLength = series.options.minPointLength || 0; 

     H.each(series.points, function (point) { 
      var plotX = point.plotX, 
       plotX2 = xAxis.toPixels(H.pick(point.x2, point.x + (point.len || 0)), true), 
       width = plotX2 - plotX, 
       widthDifference; 

      if (minPointLength) { 
       widthDifference = width < minPointLength ? minPointLength - width : 0; 
       plotX -= widthDifference/2; 
       plotX2 += widthDifference/2; 
      } 

      plotX = Math.max(plotX, -10); 
      plotX2 = Math.min(Math.max(plotX2, -10), xAxis.len + 10); 

      point.shapeArgs = { 
       x: plotX, 
       y: point.plotY + metrics.offset, 
       width: plotX2 - plotX, 
       height: metrics.width 
      }; 
      point.tooltipPos[0] += width/2; 
      point.tooltipPos[1] -= metrics.width/2; 
     }); 
    } 
}); 

/** 
* Max x2 should be considered in xAxis extremes 
*/ 
H.wrap(H.Axis.prototype, 'getSeriesExtremes', function (proceed) { 
    var axis = this, 
     dataMax, 
     modMax; 

    proceed.call(this); 
    if (this.isXAxis) { 
     dataMax = pick(axis.dataMax, Number.MIN_VALUE); 
     each(this.series, function (series) { 
      each(series.x2Data || [], function (val) { 
       if (val > dataMax) { 
        dataMax = val; 
        modMax = true; 
       } 
      }); 
     }); 
     if (modMax) { 
      axis.dataMax = dataMax; 
     } 
    } 
}); 
}(Highcharts)); 


// THE CHART 
Highcharts.chart('container', { 
    chart: { 
     type: 'xrange' 
    }, 
    title: { 
     text: 'Item List' 
    }, 
    xAxis: { 
     type: 'datetime', 
     min: Date.UTC(2014, 11, 3) 
    }, 
    yAxis: { 
     title: '', 
     categories: ['Item 1', 'Item 2'], 
     reversed: true 
    }, 
    series: [{ 
     name: 'Project 1', 
     // pointPadding: 0, 
     // groupPadding: 0, 
     borderRadius: 5, 
     pointWidth: 10, 
     data: [{ 
      x: Date.UTC(2014, 11, 3), 
      x2: Date.UTC(2014, 11, 3), 
      y: 0 
     }, { 
      x: Date.UTC(2014, 11, 6), 
      x2: Date.UTC(2014, 11, 7), 
      y: 0 
     }, 
     { 
      x: Date.UTC(2014, 11, 9), 
      x2: Date.UTC(2014, 11, 11), 
      y: 0 
     }], color: '#BF0B23' 
    }] 

}); 

JSFiddle Example

:

{ X : 중 Date.UTC (2014 년 11 일 3

예를 들어, I는 다음의 차트가), x2 : Date.UTC (2014, 11, 3), y : 0 },

날짜 범위가 너무 작아서 실제로 그래프에 표시되는 것처럼 (예 : this example의 '태양'이미지와 같은) 마커 이미지를 추가하려고하지만 마커가 있어야하는 위치를 찾을 수 없습니다. 내 JSFiddle 예제에 배치.

+0

열 시리즈 유형을 확장하기 때문에, 당신의 시리즈에 이미지를 추가하기 어렵다. 대신 선 차트와 같은 다른 차트 유형을 사용할 수 있어야합니다. http://jsfiddle.net/7gxjecnn/2/ –

답변

0

마커는 당신의 지점에 배치됩니다 :

{ 
    x: Date.UTC(2014, 11, 3), 
    x2: Date.UTC(2014, 11, 3), 
    y: 0, 

    // Like this: 
    marker: { 
    symbol: 'url(...)' 
    } 
}, 
+0

나는 거기에 갈 것이라고 생각했지만 작동하지 않는 것 같습니다 : http : // jsfiddle. net/7gxjecnn/ – ca8msm

+1

@ ca8msm은'xrange' 차트에서 지원되는 것처럼 보이지 않습니다. 그것은 차트 타입이'spline'으로 설정되었을 때 작동합니다 : http://jsfiddle.net/7gxjecnn/1. –

+0

감사합니다. 불행히도 xrange는 x 당 여러 개의 범위가 있으므로 사용해야합니다. – ca8msm

관련 문제