- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最佳答案
我能够使用plugin API使用chart.js v2.3.0获得类似的工作和 extending chart types API 。您应该能够以此为起点,并根据您的需求进行调整。
这是渲染后的样子。
请注意,这需要深入挖掘 Chart.js 的内部结构,如果它们改变了 future 工具提示的定位或呈现方式,则可能会崩溃。我还添加了一个名为 showAllTooltips
的新配置选项,以允许在某些图表上有选择地使用该插件。这应该适用于所有图表类型,但目前我仅将其用于饼图、圆环图、条形图和折线图。
话虽如此,这是上图的可行解决方案。
Chart.plugins.register({
beforeRender: function (chart) {
if (chart.config.options.showAllTooltips) {
// create a namespace to persist plugin state (which unfortunately we have to do)
if (!chart.showAllTooltipsPlugin) {
chart.showAllTooltipsPlugin = {};
}
// turn off normal tooltips in case it was also enabled (which is the global default)
chart.options.tooltips.enabled = false;
// we can't use the chart tooltip because there is only one tooltip per chart which gets
// re-positioned via animation steps.....so let's create a place to hold our tooltips
chart.showAllTooltipsPlugin.tooltipsCollection = [];
// create a tooltip for each plot on the chart
chart.config.data.datasets.forEach(function (dataset, i) {
chart.getDatasetMeta(i).data.forEach(function (sector, j) {
// but only create one for pie and doughnut charts if the plot is large enough to even see
if (!_.contains(['doughnut', 'pie'], sector._chart.config.type) || sector._model.circumference > 0.1) {
var tooltip;
// create a new tooltip based upon configuration
if (chart.config.options.showAllTooltips.extendOut) {
// this tooltip reverses the location of the carets from the default
tooltip = new Chart.TooltipReversed({
_chart: chart.chart,
_chartInstance: chart,
_data: chart.data,
_options: chart.options.tooltips,
_active: [sector]
}, chart);
} else {
tooltip = new Chart.Tooltip({
_chart: chart.chart,
_chartInstance: chart,
_data: chart.data,
_options: chart.options.tooltips,
_active: [sector]
}, chart);
}
// might as well initialize this now...it would be a waste to do it once we are looping over our tooltips
tooltip.initialize();
// save the tooltips so they can be rendered later
chart.showAllTooltipsPlugin.tooltipsCollection.push(tooltip);
}
});
});
}
},
afterDraw: function (chart, easing) {
if (chart.config.options.showAllTooltips) {
// we want to wait until everything on the chart has been rendered before showing the
// tooltips for the first time...otherwise it looks weird
if (!chart.showAllTooltipsPlugin.initialRenderComplete) {
// still animating until easing === 1
if (easing !== 1) {
return;
}
// animation is complete, let's remember that fact
chart.showAllTooltipsPlugin.initialRenderComplete = true;
}
// at this point the chart has been fully rendered for the first time so start rendering tooltips
Chart.helpers.each(chart.showAllTooltipsPlugin.tooltipsCollection, function (tooltip) {
// create a namespace to persist plugin state within this tooltip (which unfortunately we have to do)
if (!tooltip.showAllTooltipsPlugin) {
tooltip.showAllTooltipsPlugin = {};
}
// re-enable this tooltip otherise it won't be drawn (remember we disabled all tooltips in beforeRender)
tooltip._options.enabled = true;
// perform standard tooltip setup (which determines it's alignment and x, y coordinates)
tooltip.update(); // determines alignment/position and stores in _view
tooltip.pivot(); // we don't actually need this since we are not animating tooltips, but let's be consistent
tooltip.transition(easing).draw(); // render and animate the tooltip
// disable this tooltip in case something else tries to do something with it later
tooltip._options.enabled = false;
});
}
},
});
// A 'reversed' tooltip places the caret on the opposite side from the current default.
// In order to do this we just need to change the 'alignment' logic
Chart.TooltipReversed = Chart.Tooltip.extend({
// Note: tooltipSize is the size of the box (not including the caret)
determineAlignment: function(tooltipSize) {
var me = this;
var model = me._model;
var chart = me._chart;
var chartArea = me._chartInstance.chartArea;
// set caret position to top or bottom if tooltip y position will extend outsite the chart top/bottom
if (model.y < tooltipSize.height) {
model.yAlign = 'top';
} else if (model.y > (chart.height - tooltipSize.height)) {
model.yAlign = 'bottom';
}
var leftAlign, rightAlign; // functions to determine left, right alignment
var overflowLeft, overflowRight; // functions to determine if left/right alignment causes tooltip to go outside chart
var yAlign; // function to get the y alignment if the tooltip goes outside of the left or right edges
var midX = (chartArea.left + chartArea.right) / 2;
var midY = (chartArea.top + chartArea.bottom) / 2;
if (model.yAlign === 'center') {
leftAlign = function(x) {
return x >= midX;
};
rightAlign = function(x) {
return x < midX;
};
} else {
leftAlign = function(x) {
return x <= (tooltipSize.width / 2);
};
rightAlign = function(x) {
return x >= (chart.width - (tooltipSize.width / 2));
};
}
overflowLeft = function(x) {
return x - tooltipSize.width < 0;
};
overflowRight = function(x) {
return x + tooltipSize.width > chart.width;
};
yAlign = function(y) {
return y <= midY ? 'bottom' : 'top';
};
if (leftAlign(model.x)) {
model.xAlign = 'left';
// Is tooltip too wide and goes over the right side of the chart.?
if (overflowLeft(model.x)) {
model.xAlign = 'center';
model.yAlign = yAlign(model.y);
}
} else if (rightAlign(model.x)) {
model.xAlign = 'right';
// Is tooltip too wide and goes outside left edge of canvas?
if (overflowRight(model.x)) {
model.xAlign = 'center';
model.yAlign = yAlign(model.y);
}
}
}
});
关于pie-chart - 在 Chartjs 中显示饼图之外的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34199230/
我正在使用 Xcode 4.5,部署目标为 iOS 5.1 当我编译我的应用程序时,我收到以下警告,这些方法与两个大小显着增加的特定方法有关。 ld: warning: PIE disabled. A
我想使用 lief 将可执行文件转换为共享库,我注意到它只支持 pie 可执行文件。所以我想知道是否有一种方法可以将 no-pie 可执行文件转换为 pie 可执行文件。 最佳答案 不,没有,除非在链
我的 Android 项目应该生成原生可执行文件作为构建的一部分,并支持 API 14 (Android 4.0) 的所有设备。 问题是 4.0 仅支持非 pie 可执行文件,而 Android >
我有一个全屏cordova应用程序,我曾经使用下面的css作为iPhone X的缺口, padding-top: 25px; padding-top: env(safe-area-inset-top)
我指的是这个https://ecomfe.github.io/echarts/doc/example/pie1.html#-en例子。我无法隐藏饼图中的相邻标签。我已经圈出了我希望隐藏在附加图像中的标
这是我的代码: function graphDataAllChart(graphData) { $(".dataContentAllPie").empty(); nv.addGrap
这有效: perl -pi -e 's/abc/cba/g' hellofile 但这不会: perl -pie 's/cba/abc/g' hellofile 换句话说 -pi -e 有效但 -pi
在 amcharts v4 中,PIE 切片的颜色在 10 种左右的颜色后重复。就像他们有一系列颜色,他们只使用这些颜色并在完成后重复。我希望所有切片都具有独特的颜色,而无需手动创建颜色。如果可能需要
我在我的应用程序中有一个 15 秒计时器的要求,在圆形进度条动画中将在秒数的中心包含标签 下面的代码给出了从 0.0 到 1.0f 的 labelprogress,但我想将它映射到 15 秒倒计时的平
我有一个在夜间运行后台服务的应用程序。它由 alarm clock app 触发运行. 该应用整夜将手机外部 SD 卡上的数据上传到 Dropbox。它可以在以前的 Android 版本上无缝运行,但
我正在尝试从这里自定义一个饼图: https://canvasjs.com/jquery-charts/pie-chart-index-data-label-inside/ 我使用的代码如下,经过我的
我正在尝试使用 CSS PIE 显示圆 Angular ,但它不起作用。请看my website for reference .您会看到在 IE7 和 IE8 中,顶部的小登录区域没有圆 Angula
我正致力于将我们公司的 Web 应用程序带入 21 世纪,并尝试使用一些新的 CSS3 功能,如 border-radius 和 box-shadow 以获得更现代的视觉效果。然而,我们 90% 以上
有一个简单的例子:http://fsou1.ru/files/verstka_examples/14/index2.html 我在 IE 中使用 PIE.js 附加边框半径,但是当我在悬停事件上添加“
我有一个网站 here ... 在 Chrome/FF 中查看它,您会看到带有圆 Angular 的标签。 IE8 仍然显示方 Angular 。 这是我调用 PIE 的 CSS... .class-
渲染边框的 RGBA 颜色时遇到问题。边框半径的 RGBA 颜色工作正常但不是边框颜色,它不显示任何边框颜色。 CSSPie 中是否有单独的“-pie-”标签用于在边框中使用 RGBA? 我的代码:
我用 gcc -fpie test.c 编译了一个简单的 hello world c 代码,现在使用 objdump 查看二进制文件: Disassembly of section __TEXT,__
我正在使用 CSS3 pie 并在 head 标签之前通过附加的 js 文件调用它。 出于某种原因,我的背景图片出现了。我已经尝试了标准添加 z-index 和位置相对修复,但它没有显示。任何帮助指导
这是我检测和显示性别和年龄的循环。我试图在 matplotlib 饼图上绘制它,但每次它运行循环时,它都会为每个预测打开一个不同的图表。如何实时更新同一个图表。 这里我更新完整的代码 使用 Pytho
我用的是ie8,其他版本不知道。我到处都在使用派,它通常工作正常。但是,我所有的表单输入元素都有框阴影和边框半径,并且没有边框(几乎所有样式)。在 FF/Safari/Chrome 中一切都很好,但在
我是一名优秀的程序员,十分优秀!