highchart customer the bar.

fixedIncome-charts1.js(function() {var each = Highcharts.each,merge = Highcharts.merge,doc = document,math = Math,seriesTypes = Highcharts.seriesTypes,extend = Highcharts.extend,extendClass = Highcharts.extendClass,ColumnSeries = seriesTypes.column,defaultOptions = Highcharts.getOptions(),defaultPlotOptions = defaultOptions.plotOptions,css = Highcharts.css,mathAbs = math.abs,mathMax = math.max,mathCeil = math.ceil,mathMin = math.min,pick = Highcharts.pick,UNDEFINED;var defaultPlotOptions = defaultOptions.plotOptions,defaultSeriesOptions = defaultPlotOptions.line;defaultPlotOptions.customColumn = merge(defaultSeriesOptions, {borderColor: '#FFFFFF',borderRadius: 0,marker: null, pointPadding: 0.1,minPointLength: 0,stacking: 'normal',pointWidth: 20,borderWidth: 0,animation: false,shadow: false,groupPadding: 0.12,states: {hover: {brightness: 0.1,shadow: false},select: {color: '#C0C0C0',borderColor: '#000000',shadow: false}},dataLabels: {y: null,verticalAlign: null}});function defined(obj) {return obj !== UNDEFINED && obj !== null;}var CustomColumnSeries = extendClass(ColumnSeries, {type : 'customColumn',init: function () {ColumnSeries.prototype.init.apply(this, arguments);var series = this,chart = series.chart;// flag the chart in order to pad the x axischart.hasColumn = true;// if the series is added dynamically, force redraw of other// series affected by a new columnif (chart.hasRendered) {each(chart.series, function (otherSeries) {if (otherSeries.type === series.type) {otherSeries.isDirty = true;}});}},translate: function () {var series = this,chart = series.chart,options = series.options,stacking = options.stacking,borderWidth = options.borderWidth,columnCount = 0,reversedXAxis = series.xAxis.reversed,categories = series.xAxis.categories,stackGroups = {},stackKey,columnIndex,hasSeriesId = false;var currentSerieName = series.name;// console.log('currentSerieName----'+currentSerieName);if(series.name == "top1" || series.name == "top2"){hasSeriesId = true;}ColumnSeries.prototype.translate.apply(series);// Get the total number of column type series.// This is called on every series. Consider moving this logic to a// chart.orderStacks() function and call it on init, addSeries and removeSerieseach(chart.series, function (otherSeries) {var xxx = [];if (otherSeries.type === series.type && otherSeries.visible) {if (otherSeries.options.stacking) {stackKey = otherSeries.stackKey;if (stackGroups[stackKey] === UNDEFINED) {stackGroups[stackKey] = columnCount++;}columnIndex = stackGroups[stackKey];} else {columnIndex = columnCount++;}otherSeries.columnIndex = columnIndex;}});// calculate the width and position of each column based on// the number of column series in the plot, the groupPadding// and the pointPadding optionsvar data = series.data,closestPoints = series.closestPoints,categoryWidth = mathAbs(data[1] ? data[closestPoints].plotX - data[closestPoints - 1].plotX :chart.plotSizeX / ((categories && categories.length) || 1)),groupPadding = categoryWidth * options.groupPadding,groupWidth = categoryWidth - 2 * groupPadding,pointOffsetWidth = groupWidth / columnCount,optionPointWidth = options.pointWidth,pointPadding = defined(optionPointWidth) ? (pointOffsetWidth - optionPointWidth) / 2 :pointOffsetWidth * options.pointPadding,pointWidth = mathMax(pick(optionPointWidth, pointOffsetWidth - 2 * pointPadding), 1),colIndex = (reversedXAxis ? columnCount -series.columnIndex : series.columnIndex) || 0,pointXOffset = pointPadding + (groupPadding + colIndex *pointOffsetWidth - (categoryWidth / 2)) *(reversedXAxis ? -1 : 1),threshold = options.threshold || 0,translatedThreshold = series.yAxis.getThreshold(threshold),minPointLength = pick(options.minPointLength, 5);// record the new valueseach(data, function (point, index) {var plotY = point.plotY,yBottom = point.yBottom || translatedThreshold,barX = point.plotX + pointXOffset,barY = mathCeil(mathMin(plotY, yBottom)),barH = mathCeil(mathMax(plotY, yBottom) - barY),stack = series.yAxis.stacks[(point.y < 0 ? '-' : '') + series.stackKey],trackerY,shapeArgs;if(hasSeriesId){barY = barY - 3;var td = dataTop[index];var bd = dataBottom[index];var dataP = td/bd;var heightP = barH/4;if(dataP > heightP){var botomBarH = bd*barH/td;if(botomBarH < 1){botomBarH = 1;}barY = barY - 4 + botomBarH;}}else{if(barH < 1){barH = 1;}if(barH < 4){barY = barY - 4 + barH;barH = 4;}}// Record the offset'ed position and width of the bar to be able to align the stacking total correctlyif (stacking && series.visible && stack && stack[point.x]) {stack[point.x].setOffset(pointXOffset, pointWidth);}// handle options.minPointLength and tracker for small pointsif (mathAbs(barH) < minPointLength) {if (minPointLength) {barH = minPointLength;barY =mathAbs(barY - translatedThreshold) > minPointLength ? // stackedyBottom - minPointLength : // keep positiontranslatedThreshold - (plotY <= translatedThreshold ? minPointLength : 0);}trackerY = barY - 3;}extend(point, {barX: barX,barY: barY,barW: pointWidth,barH: barH});// create shape type and shape args that are reused in drawPoints and drawTrackerpoint.shapeType = 'rect';shapeArgs = extend(chart.renderer.Element.prototype.crisp.apply({}, [borderWidth,barX,barY,pointWidth,barH]), {r: options.borderRadius});if (borderWidth % 2) { // correct for shorting in crisp method, visible in stacked columns with 1px bordershapeArgs.y -= 1;shapeArgs.height += 1;}point.shapeArgs = shapeArgs;// make small columns responsive to mousepoint.trackerArgs = defined(trackerY) && merge(point.shapeArgs, {height: mathMax(6, barH + 3),y: trackerY});});}});seriesTypes.customColumn = CustomColumnSeries;})();
發佈了33 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章