android图表库——androidplot onclick问题
我正在尝试使用图书馆“androidplot”。它提供了一个新的侦听器吗?如果我将代码放在oncreate()中,它就会工作。但是如果我把onclik()放进去,它就不起作用了。有人能告诉我为什么吗? 这是一个XML文件:android图表库——androidplot onclick问题,android,androidplot,Android,Androidplot,我正在尝试使用图书馆“androidplot”。它提供了一个新的侦听器吗?如果我将代码放在oncreate()中,它就会工作。但是如果我把onclik()放进去,它就不起作用了。有人能告诉我为什么吗? 这是一个XML文件: <com.androidplot.xy.XYPlot android:id="@+id/mySimpleXYPlot" android:layout_width="743px" android:layout_height="473px"
<com.androidplot.xy.XYPlot
android:id="@+id/mySimpleXYPlot"
android:layout_width="743px"
android:layout_height="473px"
android:layout_marginTop="5px"
android:layout_marginLeft="5px"
android:layout_marginRight="0px"
title="Line Chart testing"
/>
它会起作用,但如果我把它放在onclicklistener中,它就不会起作用。代码如下:
Button oneday = (Button) findViewById(R.id.oneday);
oneday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// initialize our XYPlot reference:
mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
// add a new series
mySimpleXYPlot.addSeries(new SimpleXYSeries2(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0)));
// reduce the number of range labels
mySimpleXYPlot.getGraphWidget().setRangeTicksPerLabel(4);
// reposition the domain label to look a little cleaner:
Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget();
mySimpleXYPlot.position(domainLabelWidget, // the widget to position
45, // x position value, in this case 45 pixels
XLayoutStyle.ABSOLUTE_FROM_LEFT, // how the x position value is applied, in this case from the left
0, // y position value
YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
AnchorPosition.LEFT_BOTTOM); // point to use as the origin of the widget being positioned
// get rid of the visual aids for positioning:
mySimpleXYPlot.disableAllMarkup();
}
});
非常感谢 在“mySimpleXYPlot.disableAllMarkup();”之后尝试使用“mySimpleXYPlot.redraw();”
我很确定,图形是在创建视图时绘制的,因此,当您在第一次绘制之后进行设置时,您必须重新绘制它。我认为,如果在运行时更改图形上的某些内容,情况也是如此。在“mySimpleXYPlot.disablemarkup()”之后尝试使用“mySimpleXYPlot.redraw();”
我很确定,图形是在创建视图时绘制的,因此,当您在第一次绘制之后进行设置时,您必须重新绘制它。我认为,如果在运行时更改图表上的某些内容,情况也是如此。您所说的“它不起作用”是什么意思?它会引发异常吗?它什么都不做吗?对于onclick(),当我单击按钮时。什么都不做这两个示例之间有一个不同之处:第一个示例使用
SimpleXYSeries
,第二个示例使用SimpleXYSeries2
。尝试将第二个更改为SimpleXYSeries
,以确认这不是问题的原因。您所说的“它不起作用”是什么意思?它会引发异常吗?它什么都不做吗?对于onclick(),当我单击按钮时。什么都不做这两个示例之间有一个不同之处:第一个示例使用SimpleXYSeries
,第二个示例使用SimpleXYSeries2
。尝试将第二个更改为SimpleXYSeries
,以确认这不会导致问题。
Button oneday = (Button) findViewById(R.id.oneday);
oneday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// initialize our XYPlot reference:
mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
// add a new series
mySimpleXYPlot.addSeries(new SimpleXYSeries2(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0)));
// reduce the number of range labels
mySimpleXYPlot.getGraphWidget().setRangeTicksPerLabel(4);
// reposition the domain label to look a little cleaner:
Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget();
mySimpleXYPlot.position(domainLabelWidget, // the widget to position
45, // x position value, in this case 45 pixels
XLayoutStyle.ABSOLUTE_FROM_LEFT, // how the x position value is applied, in this case from the left
0, // y position value
YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
AnchorPosition.LEFT_BOTTOM); // point to use as the origin of the widget being positioned
// get rid of the visual aids for positioning:
mySimpleXYPlot.disableAllMarkup();
}
});