Skip to content

Commit 545c633

Browse files
committed
Work on timechart
1 parent 992dd5f commit 545c633

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
6060
mSeekBarX.setOnSeekBarChangeListener(this);
6161

6262
mChart = (LineChart) findViewById(R.id.chart1);
63+
mChart.setLogEnabled(true);
6364

6465
// no description text
6566
mChart.setDescription("");
@@ -84,8 +85,7 @@ protected void onCreate(Bundle savedInstanceState) {
8485

8586
// add data
8687
setData(20, 30);
87-
88-
mChart.animateX(2500);
88+
mChart.invalidate();
8989

9090
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
9191

@@ -109,8 +109,8 @@ protected void onCreate(Bundle savedInstanceState) {
109109
xAxis.setSpaceBetweenLabels(1);
110110

111111
// custom x-axis min / max
112-
xAxis.setAxisMinValue(curTime);
113-
xAxis.setAxisMaxValue(curTime + 100000);
112+
xAxis.setAxisMinValue(5000);
113+
xAxis.setAxisMaxValue(30000);
114114

115115
YAxis leftAxis = mChart.getAxisLeft();
116116
leftAxis.setTypeface(tf);
@@ -272,10 +272,10 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
272272
private void setData(int count, float range) {
273273

274274
ArrayList<XAxisValue> xVals = new ArrayList<XAxisValue>();
275-
for (int i = 0; i < count; i++) {
275+
for (int i = 0; i < 10; i++) {
276276

277-
long timeLong = curTime + i * 1000;
278-
xVals.add(new XAxisValue(timeLong, new Date(timeLong).toString()));
277+
long timeLong = 10000 + i * 1000;
278+
xVals.add(new XAxisValue(timeLong, i + ""));
279279
}
280280

281281
ArrayList<Entry> yVals1 = new ArrayList<Entry>();

‎MPChartLib/src/com/github/mikephil/charting/data/ChartData.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ private void checkLegal() {
194194

195195
for (int i = 0; i < mDataSets.size(); i++) {
196196
if (mDataSets.get(i).getEntryCount() > mXVals.size()) {
197-
throw new IllegalArgumentException(
198-
"One or more of the DataSet Entry arrays are longer than the x-values array of this ChartData object.");
197+
// throw new IllegalArgumentException(
198+
// "One or more of the DataSet Entry arrays are longer than the x-values array of this ChartData object.");
199199
}
200200
}
201201
}

‎MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRenderer.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,17 @@ protected void drawLabels(Canvas c, float pos, PointF anchor) {
155155
0f, 0f
156156
};
157157

158-
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
158+
for (int i = 0; i < mXAxis.getValues().size(); i++) {
159159

160-
position[0] = i;
160+
XAxisValue xVal = mXAxis.getValues().get(i);
161+
162+
position[0] = (float) xVal.getPosition();
161163

162164
mTrans.pointValuesToPixel(position);
163165

164166
if (mViewPortHandler.isInBoundsX(position[0])) {
165167

166-
String label = mXAxis.getValues().get(i).getLabel();
168+
String label = xVal.getLabel();
167169

168170
if (mXAxis.isAvoidFirstLastClippingEnabled()) {
169171

0 commit comments

Comments
 (0)