2

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

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

现在我在自定义图表时遇到了一些问题,这里是当前结果的屏幕截图 a 设法实现:

在此处输入图像描述

我的问题是:

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

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

设置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());
        }
    });
}
}

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

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

4

1 回答 1

2

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

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

于 2013-06-19T19:04:28.630 回答