android - 需要自定义 Iguana UI 工具集的帮助 :

标签 android charts infragistics iguana-ui

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

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

现在我在自定义图表本身时遇到一些问题,这是当前成功实现的结果的屏幕截图:

enter image description here

我的问题是:

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

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

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

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

更新: 我发现你可以申请:

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

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

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

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

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

关于android - 需要自定义 Iguana UI 工具集的帮助 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15600549/

相关文章:

java - 用作 View 标签的整数不起作用

android - 从 Android 库项目覆盖 Activity

r - 如何在 R 中为悬停文本配置千位分隔符?

javascript - Highcharts:如何在图表区域内添加 HTML

linux - 您会为 Linux 推荐哪种甘特图/项目管理工具?

css - 动态加载时将 CssStyle 应用于 Infragistics WebDataGrid 列

c# - 将 UltraCombo 添加到已格式化的 ToolStrip

java - kotlin 中的二维列表转换为 com.google.gson.internal.LinkedTreeMap

使用 Infragistics 组件和调整例程大小时,Winforms 应用程序在不同计算机上的显示不同

android - 在 Android 上将音频路由到蓝牙耳机(非 A2DP)