Search code examples
javaandroidteechart

Color Grid Example Android


I'm trying to make a ColorGrid graph that has the center square being a dark color and the squares around it slowly fading to white as it gets farther. I'm new to TeeChart and I checked out the examples. I'm trying to replace the series.fillSampleValues() but I'm not sure what values to include in series.add(). What are the parameters for the series.add() for ColorGrid?

Here's my code

    final LinearLayout ll = (LinearLayout) findViewById( R.id.samplegraphlayout );

    TChart chart = new TChart( ll.getContext() );
    ll.addView( chart );

    Series series = null;
    try {
        series = Series.createNewSeries(chart.getChart(), ColorGrid.class, null);
    } catch (Exception e) {
        e.printStackTrace();
    } 
    series.fillSampleValues();
    chart.addSeries(series);
    chart.getLegend().setAlignment(LegendAlignment.BOTTOM);
    chart.getHeader().setText("ColorGrid Series");
    chart.getHeader().getFont().setSize(14);

Solution

  • Here it is an example of how you could populate a ColorGrid with Random Colors:

    tChart1.getAspect().setView3D(false);
    int gridWidth = 11;
    int gridHeight = 11;
    
    ColorGrid colorGrid1 = new ColorGrid(tChart1.getChart());
    colorGrid1.setColorEach(true);
    for (int x=0; x<gridWidth; x++) {
        for (int z=0; z<gridHeight; z++) {
            colorGrid1.add(x, 1, z, new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
        }
    }
    

    Then, knowing the column (x) and row (z) of each cell, you shouldn't find too much problems to calculate the Color that corresponds to each one.