本文主要是介绍解决jofc折线图tooltip问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
之前因为设置LineChart的tooltip不起作用,不管设成什么都是是显示value值。实际上不应该设置LineChart的tooltip。如同BarChart得设置Bar的tooltip,LineChart也必须设置Dot的tooltip,这样才能在鼠标移动到点的时候显示提示。然而悲剧的是,jofc中的Dot居然没有tooltip。不过还是开源强大啊,源码一下,代码一改,把tooltip加进去,重新导出JAR包,设置好Dot的tooltip,一切就顺利了。哈哈!
Dot
@Converter(DotConverter.class)
publicstatic class Dot {
@Alias("halo-size")
privateInteger haloSize;
@Alias("dot-size")
privateInteger dotSize;
privateNumber value;
privateString colour;
@Alias("tip")
private String tooltip;
publicDot(Number value) {
this(value,null, null, null);
}
publicDot(Number value, String colour) {
this(value,colour, null, null);
}
publicDot(Number value, String colour, Integer dotSize, Integer haloSize) {
setValue(value);
setColour(colour);
setDotSize(dotSize);
setHaloSize(haloSize);
}
publicInteger getHaloSize() {
returnhaloSize;
}
publicDot setHaloSize(Integer haloSize) {
this.haloSize= haloSize;
returnthis;
}
publicInteger getDotSize() {
returndotSize;
}
publicDot setDotSize(Integer dotSize) {
this.dotSize= dotSize;
returnthis;
}
publicNumber getValue() {
returnvalue;
}
publicDot setValue(Number value) {
this.value= value;
returnthis;
}
publicString getColour() {
returncolour;
}
publicDot setColour(String colour) {
this.colour= colour;
returnthis;
}
public String getTooltip() {
return tooltip;
}
public Dot setTooltip(Stringtooltip) {
this.tooltip = tooltip;
return this;
}
}
不要忘记转换的类也要修改 DotConverter
package jofc2.util;
importjofc2.model.elements.LineChart.Dot;
importcom.thoughtworks.xstream.converters.MarshallingContext;
importcom.thoughtworks.xstream.io.path.PathTrackingWriter;
public classDotConverter extends ConverterBase<Dot> {
@Override
publicvoid convert(Dot o, PathTrackingWriter writer, MarshallingContext mc) {
writeNode(writer,"value", o.getValue(), false);
writeNode(writer,"colour", o.getColour(), true);
writeNode(writer,"dot-size", o.getDotSize(), true);
writeNode(writer,"halo-size", o.getHaloSize(), true);
writeNode(writer,"tip", o.getTooltip(), true);
}
@SuppressWarnings("unchecked")
publicboolean canConvert(Class arg0) {
returnDot.class.isAssignableFrom(arg0);
}
}
设置Dot的tooltip
LineChart.Dot dot=newLineChart.Dot(value.getNum());
dot.setTooltip(value.getName()+"<br>"+value.getNum());
lineChart.addDots(dot);
这篇关于解决jofc折线图tooltip问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!