[英]jqPlot Pie Chart highlighter
I try to use jqPlot in my jsp project. 我尝试在我的jsp项目中使用jqPlot。 I need to draw pie chart.
我需要画饼图。 With pie chart everything is ok, it works fine.
使用饼形图,一切正常,效果很好。
Then I want to show tooltip with some data when cursor is over the slice. 然后,当光标在切片上时,我想显示一些数据的工具提示。 For these, I can use highlighter which is provide by jqPlot, but I don't know how to do this.
对于这些,我可以使用jqPlot提供的荧光笔,但是我不知道该怎么做。
In .jsp file I include <script language="JavaScript"src="../../common/jsc/plugins/jqplot.highlighter.min.js"></script>
在.jsp文件中,我包含
<script language="JavaScript"src="../../common/jsc/plugins/jqplot.highlighter.min.js"></script>
My javascript code: 我的JavaScript代码:
$(document).ready(function(){ var url = 'supplyCalendarDayDetailsCharts.jsp?date=' + getEl('date').value + '&action=COG'; $.ajax({ url: url, type: "GET", dataType: "json", success: function(data) { var dataTmp = []; for (var i in data) { var dataPush = [data[i].cp_code, parseInt(data[i].value)]; dataTmp.push(dataPush); } var plot1 = jQuery.jqplot('chartdiv', [dataTmp], { seriesDefaults: { // Make this a pie chart. renderer: jQuery.jqplot.PieRenderer, rendererOptions: { // Put data labels on the pie slices. // By default, labels show the percentage of the slice. dataLabels: 'value', showDataLabels: true } } } ); } }); });
With AJAX I get json like this: [{"code":"CODE01","value":"1"},{"code":"CODE02","value":"3"}] 使用AJAX,我得到这样的json:[{“ code”:“ CODE01”,“ value”:“ 1”},{“ code”:“ CODE02”,“ value”:“ 3”}]
In pie chart I want to show value and when mouse is over slice I want to show code in tooltip. 在饼图中,我想显示值,而当鼠标悬停在切片上时,我想在工具提示中显示代码 。
Where shoud I use highlighter event? 我应该在哪里使用荧光笔事件? I tried in seriesDefaults body - after rendererOptions but maybe I use wrong options...
我在seriesDefaults正文中尝试过-在rendererOptions之后,但也许我使用了错误的选项...
Please help me, and sorry for my english. 请帮助我,对不起我的英语。 Regards Łukasz
问候Łukasz
You need to add plug-ins: 您需要添加插件:
<script type="text/javascript" src="plugins/jqplot.cursor.min.js"></script>
<script type="text/javascript" src="plugins/jqplot.highlighter.min.js"></script>
You need to add settings: 您需要添加设置:
cursor: {
style: 'pointer', // A CSS spec for the cursor type to change the
// cursor to when over plot.
show: true,
showTooltip: false, // show a tooltip showing cursor position.
},
highlighter: {
show: true,
useAxesFormatters: false,
tooltipLocation:'n',
tooltipSeparator:', ',
tooltipFormatString: '%s%d',
fadeTooltip:'fast',
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.