Skip to content

Commit 9973b2b

Browse files
committed
修复横轴显示bug;
1 parent d806706 commit 9973b2b

File tree

2 files changed

+15
-40
lines changed

2 files changed

+15
-40
lines changed

app/src/main/java/com/bin/david/smartchart/ScatterChartActivity.java

+14-40
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.ArrayList;
2929
import java.util.List;
30+
import java.util.Random;
3031

3132
public class ScatterChartActivity extends AppCompatActivity {
3233

@@ -43,49 +44,22 @@ protected void onCreate(Bundle savedInstanceState) {
4344
Resources res = getResources();
4445
FontStyle.setDefaultTextSpSize(this,12);
4546
List<String> chartYDataList = new ArrayList<>();
46-
chartYDataList.add("Tokyo");
47-
chartYDataList.add("Paris");
48-
chartYDataList.add("Hong Kong");
49-
chartYDataList.add("Singapore");
50-
chartYDataList.add("Sydney");
51-
chartYDataList.add("Milano");
52-
chartYDataList.add("Shanghai");
53-
chartYDataList.add("Beijing");
54-
chartYDataList.add("Madrid");
55-
chartYDataList.add("Moscow");
56-
chartYDataList.add("Seoul");
57-
chartYDataList.add("Bangkok");
47+
for(int i =0; i <100;i++){
48+
chartYDataList.add("huang");
49+
chartYDataList.add("li");
50+
}
5851
List<LineData> ColumnDatas = new ArrayList<>();
5952
ArrayList<Double> tempList1 = new ArrayList<>();
60-
tempList1.add(26d);
61-
tempList1.add(35d);
62-
tempList1.add(40d);
63-
tempList1.add(-20d);
64-
tempList1.add(26d);
65-
tempList1.add(35d);
66-
tempList1.add(-40d);
67-
tempList1.add(10d);
68-
tempList1.add(26d);
69-
tempList1.add(-15d);
70-
tempList1.add(40d);
71-
tempList1.add(10d);
53+
Random random = new Random();
54+
for(int i =0; i <100;i++){
55+
tempList1.add((double)random.nextInt(70));
56+
tempList1.add((double)random.nextInt(70));
57+
}
7258
LineData columnData1 = new LineData("Temperature","℃", IAxis.AxisDirection.RIGHT,getResources().getColor(R.color.arc3),tempList1);
73-
ArrayList<Double> humidityList = new ArrayList<>();
74-
humidityList.add(60d);
75-
humidityList.add(50d);
76-
humidityList.add(30d);
77-
humidityList.add(65d);
78-
humidityList.add(60d);
79-
humidityList.add(100d);
80-
humidityList.add(80d);
81-
humidityList.add(65d);
82-
humidityList.add(60d);
83-
humidityList.add(50d);
84-
humidityList.add(30d);
85-
humidityList.add(65d);
86-
LineData columnData2 = new LineData("Humidity","RH%",getResources().getColor(R.color.arc2),humidityList);
59+
//ArrayList<Double> humidityList = new ArrayList<>();
60+
8761
ColumnDatas.add(columnData1);
88-
ColumnDatas.add(columnData2);
62+
// ColumnDatas.add(columnData2);
8963
ChartData<LineData> chartData2 = new ChartData<>("Scatter chart",chartYDataList,ColumnDatas);
9064

9165
lineChart.setLineModel(LineChart.CURVE_MODEL);
@@ -142,7 +116,7 @@ protected void onCreate(Bundle savedInstanceState) {
142116
PointStyle style = legendPoint.getPointStyle();
143117
style.setShape(PointStyle.RECT);
144118
lineChart.getLegend().setPercent(0.2f);
145-
lineChart.getHorizontalAxis().setRotateAngle(45);
119+
//lineChart.getHorizontalAxis().setRotateAngle(45);
146120
lineChart.getHorizontalAxis().setAxisDirection(IAxis.AxisDirection.TOP);
147121
lineChart.getProvider().setDrawLine(false);
148122
lineChart.getHorizontalAxis().setFormat(new IFormat<String>() {

chart/src/main/java/com/daivd/chart/component/axis/HorizontalAxis.java

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void computeScale(ChartData<? extends BarData> chartData, Rect rect, Pain
4141
String formatData = formatData(xData);
4242
if (maxLength < formatData.length()) {
4343
maxLengthXData = formatData;
44+
maxLength = formatData.length();
4445
}
4546
}
4647
textWidth = (int) paint.measureText(maxLengthXData);

0 commit comments

Comments
 (0)