- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这段代码,它试图启用 qtip in plottable.js
var store = [{ Name:"Item 1", Total:18.73424242 },
{ Name:"Item 2", Total:7.34311 },
{ Name:"Item 3", Total:3.1235535},
{ Name:"Item 4", Total:12.763574}];
var colorScale = new Plottable.Scales.Color();
var legend = new Plottable.Components.Legend(colorScale);
var pie = new Plottable.Plots.Pie()
.attr("fill", function(d){ return d.Name; }, colorScale)
.addDataset(new Plottable.Dataset(store))
.attr("qtip2-title", function(d) { return '<div class="bartip">' + d.Name + " (" + d.Total.toFixed(2) + ')</div>'; })
.addClass("tooltipped")
.sectorValue(function(d){ return d.Total; } )
.labelsEnabled(true);
new Plottable.Components.Table([[pie, legend]]).renderTo("#chart");
/*
// Adding this block does not work
$(".tooltipped rect").qtip({
overwrite: true,
content: {
text: function() {
return $(this).attr("qtip2-title");
}
},
position: {
my: "bottom middle",
at: "top middle"
},
style: {
classes: "qtip-light"
}
});
*/
<link href="https://rawgithub.com/palantir/plottable/develop/plottable.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.1/basic/jquery.qtip.css" rel="stylesheet" />
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://rawgithub.com/palantir/plottable/develop/plottable.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.1/basic/jquery.qtip.js"></script>
<div id="container">
<svg id="chart" width="350" height="350"></svg>
</div>
正如您所注意到的,qtip2 Javascript 代码似乎不起作用。我怎样才能让它工作?
最佳答案
第 1 步
您需要包含 jQuery,因为 qTip 依赖于 jQuery。
第 2 步
将工具提示信息存储在某个属性中,这里我使用属性名称title
.attr("title", function(d) {
return "" + d.Total.toFixed(2);//storing the tooltip info in attribute title
})
将类工具提示添加到路径。
.attr("class", "tooltipped")
第3步
使用 jQuery 选择器将其附加到所有具有类 tooltipped
的路径
// Adding this block which will work
//selector to select all path with class tooltipped
$(".tooltipped").qtip({
overwrite: true,
content: {
text: function(d) {
return ($(this).attr("title"));//returning the tooltip
}
},
position: {
at: "top middle"
},
style: {
classes: "qtip-light"
}
});
工作代码here或如下:
var store = [{
Name: "Item 1",
Total: 18.73424242
}, {
Name: "Item 2",
Total: 7.34311
}, {
Name: "Item 3",
Total: 3.1235535
}, {
Name: "Item 4",
Total: 12.763574
}];
var colorScale = new Plottable.Scales.Color();
var legend = new Plottable.Components.Legend(colorScale);
var pie = new Plottable.Plots.Pie()
.attr("fill", function(d) {
return d.Name;
}, colorScale)
.addDataset(new Plottable.Dataset(store))
.attr("title", function(d) {
return "" + d.Total.toFixed(2);//storing the tooltip info in attribute title
})
.attr("class", "tooltipped")
.sectorValue(function(d) {
return d.Total;
})
.labelsEnabled(true);
new Plottable.Components.Table([
[pie, legend]
]).renderTo("#chart");
// Adding this block does not work
//selector to select all path with class tooltipped
$(".tooltipped").qtip({
overwrite: true,
content: {
text: function(d) {
return ($(this).attr("title"));//returning the tooltip
}
},
position: {
at: "top middle"
},
style: {
classes: "qtip-light"
}
});
<link href="https://rawgithub.com/palantir/plottable/develop/plottable.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.1/basic/jquery.qtip.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://rawgithub.com/palantir/plottable/develop/plottable.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.1/basic/jquery.qtip.js"></script>
<div id="container">
<svg id="chart" width="350" height="350"></svg>
</div>
关于javascript - 如何在 Plottable.js/D3.js 制作的 Piechart 中启用 qtip2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125268/
我在饼图上设置了 2 个值。我想为它制作动画。但我想改变动画方式。所有动画都是从右到左的角度。我想做从左到右的角度。如何更改动画方向? 编辑 1 : 图书馆: MPAndroidChart 编辑 2
在 MPAndroidChart饼图,是否可以在值顶部显示标签? 最佳答案 您可以定义自定义 CustomPieChartRenderer它是 PieChartRenderer 的子类并覆盖我们感兴趣
我正在使用 Angular 图表(以便在显示图表和其他内容时简化我的生活)。到目前为止,it had been pretty straightforward我能够完美地呈现我的饼图。 HTML:
我们有一个带有饼图的 Activity 页面。目前,每个部分的字体都非常小。 Our pie chart with its small font size 这是我们的代码: package tech.
我想创建一个 Google Pie Chart . 我想要的是在页面首次加载时创建图表的精美动画。我试过的是这样的: google.load("visualization",
我有一个带有复选框和 2 个动画图表的应用程序:饼图和条形图。选中复选框时,将触发向图表添加新数据的方法。当复选框被 *un* 选中时,会触发从图表中删除数据的方法。 当我点击复选框时速度不是很快,一
我试图弄清楚如何获取和更新 JavaFX 中一组动态创建的饼图中的现有数据。这些饼图都保存在 ArrayList 中。第一个任务是弄清楚如何获取该数据。 当我从一组流动数据源动态创建这些饼图时,我无法
我尝试为 PieChart 的每个“切片”显示一个工具提示,与 Chart.js 中的类似: 我找到了this answer基本上试图在相同的框架中实现相同的目标。它有两个赞成票,从其他(已接受的)答
首先要感谢 HighCharts。好吧,我正在 jQuery Mobile 中使用 HighCharts 构建饼图。 我正在显示几个饼图(最多 6 个图表),这些饼图是根据响应数据在 Ajax 成功回
在我的 Android 应用程序中,我实现了一个 MPAndroidChart 饼图。我正在根据我的要求得到一切。但我无法阻止饼图中的透明颜色。我该如何解决这个问题? 这是我的示例代码 mCh
我正在使用 MPAndroidChart 库制作饼图。我想用小数显示饼图值。我想保留 % 符号。 This自 MPAndroidChart 版本 3.0.0 发布以来,旧的类似问题的解决方案无效 更新
目前我用的是GITHUB的MPAndroidChart,画饼图显示两行文字,每行颜色不同,字号不同,查了源码,中间的文字是一个字符串对象,尝试使用: PAINT paint = pie_chart.g
当我在 javafx 中构建饼图时,边界线始终为白色。(我可以使用 css 设置默认切片颜色)。如何为边界线设置自定义颜色? 最佳答案 将一些 CSS 应用于 standard chart sampl
我在尝试获取单击饼图所选切片的值时遇到了很大的麻烦。 文档说: selection_array: An array of selected objects, each one describing a
我正在使用 MPAndroidChart . 我想删除饼图上的百分比值。我怎样才能做到这一点? 最佳答案 如果不绘制入口值,请调用:pieData.setDrawValues(false) 如果不绘制
得到如下代码: Legend legend = mChart.getLegend(); legend.setLabels(new String[]{"aaaaa", "bbbbb",
这是我的代码: SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableStri
我已经使用 achartengine 实现了一个饼图。饼图的图例显示在图表底部的一行中,如下所示: oA oB oC oD 但我希望图例以多行显示,每行一个标签,如下所示: 一个 B C oD 任何帮
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
当我将每个部分悬停时,我想显示 pieChart 每个部分的值(不是百分比,而是计算百分比之前的实际值) 这是我的饼图: 我在 Primefaces 的用户指南中没有找到这个选项。 最佳答案 P
我是一名优秀的程序员,十分优秀!