The Y axis shows only the highest and lowest values,no setShowOnlyMinMax Method. How do I implement this?
v3.0.2 no setShowOnlyMinMax Method
You could implement a IAxisValueFormatter
and do something like this
@Override
public String getFormattedValue(float value, AxisBase axis) {
int firstNumber = SOME_NUMBER;
int lastNumber = SOME_OTHER_NUMBER
if(value==firstNumber || value == lastNumber)
return String.valueOf(value);
else
return "";
}
}
I did it by other means

you maybe like this
@oisx1 Excellent
你可以修改源码中CandleStickChartRender的DrawValues函数
`@Override
public void drawValues(Canvas c) {
// if values are drawn
//if (isDrawingValuesAllowed(mChart))
{
List<ICandleDataSet> dataSets = mChart.getCandleData().getDataSets();
for (int i = 0; i < dataSets.size(); i++) {
ICandleDataSet dataSet = dataSets.get(i);
if (!shouldDrawValues(dataSet))
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
mXBounds.set(mChart, dataSet);
float[] positions = trans.generateTransformedValuesCandle(
dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);
float yOffset = Utils.convertDpToPixel(5f);
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
float maxY = 0, minY = Float.MAX_VALUE;
for (int k = mXBounds.min; k < mXBounds.max; k++) {
CandleEntry en = dataSet.getEntryForIndex(k);
if (en == null)
continue;
if (en.getHigh() > maxY)
maxY = en.getHigh();
else if (en.getLow() < minY)
minY = en.getLow();
}
Log.i(Float.toString(maxY), Float.toString(minY));
for (int j = 0; j < positions.length; j += 2) {
float x = positions[j];
float y = positions[j + 1];
if (!mViewPortHandler.isInBoundsRight(x))
break;
if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))
continue;
CandleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
float high = entry.getHigh();
float low = entry.getLow();
if(high == maxY)
{
drawValue(c, dataSet.getValueFormatter(), high, entry, i, x, y - yOffset, dataSet.getValueTextColor(j / 2));
}
if(low == minY)
{
float[] matrix = new float[]{ 0, entry.getLow() * mAnimator.getPhaseY() };
trans.pointValuesToPixel(matrix);
drawValue(c, dataSet.getValueFormatter(), low, entry, i, x, matrix[1] + 2 * yOffset, dataSet.getValueTextColor(j / 2));
}
/*
if (dataSet.isDrawValuesEnabled()) {
drawValue(c,
dataSet.getValueFormatter(),
entry.getHigh(),
entry,
i,
x,
y - yOffset,
dataSet
.getValueTextColor(j / 2));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
Drawable icon = entry.getIcon();
Utils.drawImage(
c,
icon,
(int)(x + iconsOffset.x),
(int)(y + iconsOffset.y),
icon.getIntrinsicWidth(),
icon.getIntrinsicHeight());
}*/
}
//MPPointF.recycleInstance(iconsOffset);
}
}
}`
然后重载drawValue可以定制样式
@oisx1 大神,mXBounds、MPPointF、shouldDrawValues是什么啊?
(What is mXBounds, MPPointF and shouldDrawValues?)
Most helpful comment
you maybe like this