Repository: PhilJay/MPAndroidChart

Issue #4483: double/duplicate colors when calling setColors() in ScatterChart
Created: 2019-04-04T21:58:34Z
When using a scatter chart graph and calling the function setColors(), the colors set for a specific index do not match with the data on the graph. so in the code below, if I want only index 0 to be Blue and the rest to be Green, both the Entry values for 0 and 1 will be blue. This will increment so if I want only index 1 to be blue, indices 2 and 3 will be Blue while the others will be Green. Once the indices are past the length/2, this would be 5 in the example below, they will not color in the data at all. In the label of the X axis at the bottom, it does appear to be correct though.
public class ScatterChartActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_scatter_chart);

		ScatterChart scatterChart = findViewById(R.id.scatterchart);

		float[] xArray = new float[] {1,2,3,4,5,6,7,8,9,10};
		float[] yArray = new float[] {1,2,3,4,5,6,7,8,9,10};
		List<Integer> colors = new ArrayList<>();
		List<Entry> entries = new ArrayList<>();
		for(int i=0; i < xArray.length; i++) {
			if(i==0)
				colors.add(Color.BLUE);
			else
				colors.add(Color.GREEN);
			entries.add(new Entry(xArray[i], yArray[i]));
		}

		ScatterDataSet dataSet = new ScatterDataSet(entries, "data");
		dataSet.setColors(colors);
		dataSet.setValueTextColor(Color.WHITE);

		ScatterData data = new ScatterData(dataSet);
		scatterChart.setData(data);
		scatterChart.invalidate();
	}
}

the xml


    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ScatterChartActivity">
        <com.github.mikephil.charting.charts.ScatterChart
            android:id="@+id/scatterchart"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>

<
Below is when index that should be Blue == 0;

Below is when the index that should be Blue == 1

Duplicate issue #4571: Scatter Chart displays WRONG COLOR for each point
Created: 2019-06-12T10:08:48Z
Refer to the code below,  the colors of points shown on the scatter chart is not equal to the color list, ColorTemplate.MATERIAL_COLORS.
MyScatterDataSet  set1 = new MyScatterDataSet(yVals1, "DS 1");
 set1.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
set1.setColors(ColorTemplate.MATERIAL_COLORS);



For Example,
while ColorTemplate.MATERIAL_COLORS = [a, b, c, d]
the chart displayed points with colors, [a, a, b, b]
To workaround that, I have override your ScatterDataSet class as shown below.
Then, the colors is displayed as I expected, [a, b, c, d]
public class MyScatterDataSet extends ScatterDataSet {
    static int currentIndex = 0;

    public MyScatterDataSet(List<Entry> yVals, String label) {
        super(yVals, label);
    }

    @Override
    public int getColor(int index) {
        int ret =super.getColor(currentIndex);
                currentIndex+=1;
        return ret;
    }
}

I hope you can fix this bug. Thank you!

Closing comment (2019-06-12T10:15:53Z): I ve found out that its
Duplicate of #4483
However, it has not been fixed.
It's not appearing on the IOS version. So, I will regard it as a bug