2012-09-13 3 views
2

나는 홈 화면 위젯의 차트를 그릴 AndroidPlot를 사용하는 것을 시도하고있다. 나는 일반 응용 프로그램에서, 그것은 사용자 지정보기를 사용하는 것을 알고 내가 본 것과 (Android: AppWidget with custom view not working), 해결 방법은 imageView에서 비트 맵으로이 렌더링하는 것입니다. AndroidPlot : AppWidget에서 차트를 렌더링하는 방법?

는 지금은 AndroidPlot에 대한 빠른 코드를 촬영하고 바이더 클래스에 넣어하지만 내가 홈 화면에 드롭하면 아무것도 렌더링하지 않는 것 같습니다했습니다.

이 코드와 원래의 빠른 시작 코드의 차이점은 빠른 시작의 경우 Activity.findViewById을 활용하지만 분명히 여기서는 사용할 수 없다는 것입니다.

는 아무도 내가 빈 렌더링의 원인이 될 수 잘못하고 있어요 것을 여기서 뭔가를 볼 수 있을까요? 제공 할 수있는 도움을 주시면 감사하겠습니다.

private Bitmap getChartImage(Context context) 
{ 

    // initialize our XYPlot reference: 
    mySimpleXYPlot = new XYPlot(context, "My Simple XYPlot"); 

    mySimpleXYPlot.setDrawingCacheEnabled(true); 

    // add a new series 
    mySimpleXYPlot.addSeries(new SimpleXYSeries(), 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.measure(150, 150); 
    //mySimpleXYPlot.layout(0, 0, 150, 150); 


    Bitmap bmp = mySimpleXYPlot.getDrawingCache(); 

    return bmp; 
} 

답변

1

실제로 비트 맵이 비어 있는지 살펴 보셨습니까? 내 생각 엔 비트 맵 괜찮 및 문제가 코드 덩어리 외부에 존재합니다. 이 example usage of a widget with AndroidPlot을 살펴보십시오. 최소한의 슈퍼 버전이며 확실히 작동합니다. 희망이 당신을 위해 거기에 해결책은 : 거기

+0

그는 어떻게 레이아웃을 사용하기 전에 차트의 크기를 계산 했습니까? 150은 하드 코드 된 것입니다 ... –

관련 문제