需要帮助定制Iguana UI工具集:

时间:2013-03-24 15:48:47

标签: android charts infragistics iguana-ui

我目前正在开发一个需要显示图表的应用程序,我选择了IguanaUI工具集来显示应用程序中的图表:

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

现在我面临着自定义图表的一些问题,这里有一个屏幕截图,显示了当前的成果:

enter image description here

我的问题是:

  1. 橙色:如果您看到Y轴标签被“切断”并且未显示全长。 我想展示完整的标签。 (包括由于某种原因从底部被切断的0)

  2. 绿色:我想从图表背景中删除黑条,并设置我自己的背景图像。

  3. android:background设置为XML布局文件中的图表对象,将背景设置为整个对象(包括轴),并且不删除黑条。

    我希望图像仅应用于列区域(不带轴)。

    更新 我发现你可以申请:

    dataChart.setGridDisplayType(GridDisplayType.NONE);
    

    DataChart对象,但这也会移除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());
            }
        });
    }
    }
    

    有没有人有使用此工具的经验? 我整天都在他们的文档中查看如何执行这些任务,但到目前为止没有结果。

    任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:2)

在当前发布的IguanaUI版本中,删除网格的最佳选择是使用空或透明纯色画笔调用setMinorBrush(),setMajorBrush()和setStripBrush()。

对于要剪裁的垂直轴标签,您可以增加轴的大小以处理剪裁标签左侧或右侧的情况。目前无法解决垂直轴顶部和底部的裁剪。