2013-03-24 29 views
2

我目前正在開發一個需要顯示圖表的應用程序,我選擇IguanaUI工具設置爲顯示在應用程序中圖表:需要幫助,定製UI鬣蜥設置工具:

http://www.infragistics.com/products/android/

現在我「M面臨的一些問題與自定義圖表它的自我,這裏目前結果的管理,以實現屏幕截圖:

enter image description here

我的問題:

  1. 橙:,如果你看到的Y軸標籤是「切斷」,並且不顯示完整長度。 我想顯示完整的標籤。 (包括由於某種原因從底部切斷的0)

  2. 綠色:我想從圖表背景中移除黑色條紋並設置我自己的背景圖像。

設置android:background到圖表對象中的XML佈局文件,設置背景整個對象(包括軸),並且不消除黑色條帶。

我希望圖像僅適用於列區域(不含軸)。

UPDATE: 我發現,你可以申請:

dataChart.setGridDisplayType(GridDisplayType.NONE); 

到​​對象,但是這消除了Axis以及不僅內部網格。

UPDATE2:這是我ChartFragment創建圖表:

public class ChartFragment extends Fragment 
{ 
private Tab tab; 

private static final String TAG = ChartFragment.class.getSimpleName(); 
LinearLayout fragmetLayout, llParameterContainer; 
private DataChart dataChart; 
private List<String> categories; 
private List<Float> column1; 
private List<Float> column2; 
private List<List<Float>> columnList; 
TextView tabName; 


public ChartFragment(Tab tab) 
{ 
    this.tab = tab; 
} 

/** (non-Javadoc) 
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) 
*/ 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{ 
    if (container == null) { 
     // We have different layouts, and in one of them this 
     // fragment's containing frame doesn't exist. The fragment 
     // may still be created from its saved state, but there is 
     // no reason to try to create its view hierarchy because it 
     // won't be displayed. Note this is not needed -- we could 
     // just run the code below, where we would create and return 
     // the view hierarchy; it would just never be used. 
     return null; 
    } 

    fragmetLayout = (LinearLayout)inflater.inflate(R.layout.chart_fragment_layout, container, false); 
    createData(); 
    createChart(); 
    createUI(); 

    return fragmetLayout; 
} 


/* 
private void createData() { 

    categories=new ArrayList<String>(); 
    column1=new ArrayList<Float>(); 
    column2=new ArrayList<Float>(); 
    columnList = new ArrayList<List<Float>>(); 

    Random random=new Random(); 
    float value1=25.0f; 
    float value2=25.0f; 

    for(int i=0; i<20; ++i) { 
     value1+=2.0*(random.nextFloat()-0.5f); 
     value2+=2.0*(random.nextFloat()-0.5f); 

     categories.add(Integer.toString(i)); 
     column1.add(value1); 
     column2.add(value2); 
    }  
} 
*/ 


private void createData() 
{    
    categories=new ArrayList<String>(); 
    column1=new ArrayList<Float>(); 
    column2=new ArrayList<Float>(); 
    columnList = new ArrayList<List<Float>>(); 

    for (int i=0; i < tab.getChart().getChartMeasuresList().size(); i++) 
    { 
     //categories.add(Integer.toString(i)); //the x axis. 
     Measure tempMeasure = tab.getChart().getChartMeasuresList().get(i); 
     final int measureDataSize = tempMeasure.getMeasureData().size(); 
     Log.d(TAG, "current tempMeasure: " + tempMeasure.getMeasureData().toString() + " with: "+ measureDataSize + " measure data items."); 
     for (int j=0; j < measureDataSize; j++) 
     { 
      if (i == 0) 
      { 
       categories.add(tempMeasure.getMeasureData().get(j).getLabel()); 
      } 
      column1.add(Float.valueOf(tempMeasure.getMeasureData().get(j).getValue())); //column data 
      Log.d(TAG, "add value " + tempMeasure.getMeasureData().get(j).getValue() + " at label/category: "+ tempMeasure.getMeasureData().get(j).getLabel()); 
      //column2.add(value2); //column2 data 
     } 
     columnList.add(column1); 
     column1=new ArrayList<Float>(); 
    }  
} 

private void updateData() { 
    /* 
    Random random=new Random(); 
    float value1=25.0f; 
    float value2=25.0f; 

    for(int i=0; i<categories.size(); ++i) { 
     value1+=2.0*(random.nextFloat()-0.5f); 
     value2+=2.0*(random.nextFloat()-0.5f); 

     column1.set(i, value1); 
     column2.set(i, value2); 
    } 
    */ 
} 

private void createChart() { 
    dataChart=(DataChart) fragmetLayout.findViewById(R.id.dataChart); // get the empty chart view from the activity layout 
    dataChart.setHorizontalZoomEnabled(true);   // allow horizontal zooming 
    dataChart.setVerticalZoomEnabled(false);   // don't allow vertical zooming 
    dataChart.setGridDisplayType(GridDisplayType.BACK); 
    dataChart.setBackgroundColor(getResources().getColor(R.color.light_gray)); 

    // set up an x axis 
    CategoryXAxis categoryAxis=new CategoryXAxis(); 
    categoryAxis.setVisibility(View.VISIBLE); 
    categoryAxis.setDataSource(categories);    // tell the axis about the data table 
    Brush brush = categoryAxis.getLabelBrush(); 
    categoryAxis.setLabelTextSize(20); 
    brush.setColor(Color.BLACK); 
    categoryAxis.setGap(1.0f); 
    categoryAxis.setLabelBrush(brush); 
    categoryAxis.setLabelFormatter(new CategoryAxis.LabelFormatter() { 
     public String format(CategoryAxis axis, Object item) { 
      return (String)item;      // return the axis item as a string 
     } 
    }); 
    //categoryAxis.setBrushes(Color.BLACK); 
    dataChart.scales().add(categoryAxis);    // all axes must be added to the chart's scales collection 

    // set up a y axis 

    NumericYAxis valueAxis=new NumericYAxis(); 
    valueAxis.setLabelTextSize(15); 
    valueAxis.labelAreaRect.set(30, 30, 30, 30); 
    valueAxis.setVisibility(View.VISIBLE); 

    Brush brush2 = valueAxis.getLabelBrush(); 
    brush2.setColor(Color.BLACK); 
    valueAxis.setLabelBrush(brush2); 
    valueAxis.setMinimumValue(-10.0f); 
    // valueAxis.setMaximumValue(110.0f); 
    //valueAxis.setMinimumValue(0.0f);     // the random data look much nicer with a fixed axis range 
    //valueAxis.setMaximumValue(50.0f);     // the random data look much nicer with a fixed axis range 
    valueAxis.setLabelFormatter(new NumericAxis.LabelFormatter() { 
     public String format(NumericAxis axis, float item, int precision) { 
      if(precision!=numberFormat.getMinimumFractionDigits()) { 
       numberFormat.setMinimumFractionDigits(precision); // set the formatting precision 
       numberFormat.setMaximumFractionDigits(precision); // set the formatting precision 
      } 

      return numberFormat.format(item);      // return item as a string 
     } 

     final NumberFormat numberFormat=NumberFormat.getInstance(); // numeric formatter for axis values 
    }); 
    dataChart.scales().add(valueAxis);     // all axes must be added to the chart's scales collection 

    for (int i=0; i < columnList.size(); i++) 
    { 
     ValueCategorySeries series=new ColumnSeries(); 
     series.setCategoryAxis(categoryAxis);   // tell the series its x axis 
     series.setValueAxis(valueAxis);     // tell the series its y axis 
     series.setValueMember("");      // tell the series the data rows are the values 
     Log.d(TAG, "setting serias_"+i+": "+columnList.get(i).toString()); 
     series.setDataSource(columnList.get(i));     // tell the series the data table 
     dataChart.series().add(series);     // add the series to the chart 
    } 
    /* 
    { 
     ValueCategorySeries series=new ColumnSeries(); 
     series.setCategoryAxis(categoryAxis);   // tell the series its x axis 
     series.setValueAxis(valueAxis);     // tell the series its y axis 
     series.setValueMember("");      // tell the series the data rows are the values 
     series.setDataSource(column1);     // tell the series the data table 
     dataChart.series().add(series);     // add the series to the chart 
    } 

    { 
     ValueCategorySeries series=new ColumnSeries(); 
     series.setCategoryAxis(categoryAxis);   // tell the series its x axis 
     series.setValueAxis(valueAxis);     // tell the series its y axis 
     series.setValueMember("");      // tell the series the data rows are the values 
     series.setDataSource(column2);     // tell the series the data table 
     dataChart.series().add(series);     // add the series to the chart 
    } 
    */ 
} 


private void createUI() { 
    Button updateButton=(Button) fragmetLayout.findViewById(R.id.updateButton); 

    updateButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View arg0) { 
      updateData(); 

      for(Series series: dataChart.series()) { 
       series.notifyDataReset(); 
      } 
     } 
    }); 

    Button overlapButton=(Button) fragmetLayout.findViewById(R.id.overlapButton); 

    overlapButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View arg0) { 
      CategoryXAxis categoryAxis=(CategoryXAxis)dataChart.scales().get(0); 

      categoryAxis.setOverlap(2.0f*new Random().nextFloat()-1.0f); 
     } 
    }); 

    Button gapButton=(Button) fragmetLayout.findViewById(R.id.gapButton); 

    gapButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View arg0) { 
      CategoryXAxis categoryAxis=(CategoryXAxis)dataChart.scales().get(0); 

      categoryAxis.setGap(new Random().nextFloat()); 
     } 
    }); 
} 
} 

有沒有人有這個工具的經驗嗎? 我一整天都在看他們的文檔,以瞭解如何執行這些任務,但目前爲止沒有結果。

任何幫助,將不勝感激。謝謝。

+0

問題#1在這裏回答了這裏的線索:http://www.infragistics.com/community/forums/t/76694.aspx – alhalama 2013-04-24 00:40:15

+0

我已經去過這裏論壇,看到這個答案,這並沒有幫助我。 – 2013-04-24 08:45:08

+0

你能提供你用來創建圖表的代碼嗎? – alhalama 2013-04-24 20:48:53

回答

2

在當前發佈的IguanaUI版本中,刪除網格的最佳選擇是用空或透明純色畫筆調用setMinorBrush(),setMajorBrush()和setStripBrush()。

對於被裁剪的垂直軸標籤,可以增加軸的尺寸以處理標籤左側或右側被裁剪的情況。目前無法解決垂直軸頂部和底部的裁剪問題。