摘录


package com.tony.chartdemo;

import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;

import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.components.LimitLine; import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.utils.Utils;

import java.util.ArrayList; import java.util.List;

/* * Created by Tony on 2016/7/19. /

public class LineChartLegend extends android.support.v4.app.Fragment { private LineChart lineChart;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_linechart_legend, null);
    initView(view);
    initLineChart();
    setData();
    return view;
}

private void initView(View view) {
    lineChart = (LineChart) view.findViewById(R.id.lineChart_legend);

}

private void initLineChart() {
    //设置X轴方向的动画
    lineChart.animateX(500);
    lineChart.setPinchZoom(true);
    lineChart.setNoDataTextDescription("暂无数据");
    //添加一个标记,有点像地图的覆盖物
    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
    lineChart.setMarkerView(mv);

    //实例化一个限制线及其样式
    LimitLine l = new LimitLine(50f,"暴晒");
    l.setLineWidth(Utils.convertDpToPixel(2));
    l.setLineColor(getResources().getColor(android.R.color.holo_red_light));
    l.setTextSize(22);
    l.enableDashedLine(30,10,10);

    XAxis xAxis = lineChart.getXAxis();
    //设置X轴上标签的显示位置
    xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
    xAxis.setGranularity(1f);
    xAxis.setCenterAxisLabels(true);
    //设置与X轴垂直的表格线是虚线
    xAxis.enableGridDashedLine(50,10,10);

    YAxis leftYAxis = lineChart.getAxisLeft();
    //设置一个限制线
    leftYAxis.addLimitLine(l);
    //设置与Y轴垂直的表格线是虚线
    leftYAxis.enableGridDashedLine(50,10,10);

    YAxis rightYAxis = lineChart.getAxisRight();
    //隐藏Y右轴
    rightYAxis.setEnabled(false);

}
//设置数据
private void setData() {
    LineDataSet set1;
    int[] ints = {32, 45, 67, 65, 76, 54};
    List<Entry> entryList = new ArrayList<>();

    for (int i = 0; i < ints.length; i++) {
        Entry e = new Entry(i+1,ints[i]);
        entryList.add(e);
    }
    if (lineChart.getData() != null && lineChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) lineChart.getData().getDataSetByIndex(0);
        set1.setValues(entryList);
        lineChart.getData().notifyDataChanged();
        lineChart.notifyDataSetChanged();
    } else {
        set1 = new LineDataSet(entryList,"111111");
        set1.setColor(getResources().getColor(android.R.color.holo_green_light));
        set1.setLineWidth(2f);
        set1.setDrawCircleHole(true);
        //设置lineChart每个点空心圆的颜色
        set1.setCircleColor(getResources().getColor(android.R.color.holo_red_dark));
        //设置空心圆圆的半径
        set1.setCircleRadius(10f);
        //设置内圆的颜色
        set1.setCircleColorHole(getResources().getColor(android.R.color.background_dark));
        //设置内圆的半径
        set1.setCircleHoleRadius(5f);
        //射线下面的阴影部分
        set1.setDrawFilled(true);
        //设置折线下面阴影部分的图片

点评

NULL

原文

点击这里查看原文

其它

本帖内容由21QA云收藏工具自动生成,欢迎使用。

系统消息 若觉得内容不错,请点击左上角的"赞"图标,以优化网站的内容呈现。 另外,请及时验证注册邮箱,否则收不到21QA发出的红包。 官方Q群:250203055

asked 01 Aug, 16:21

%E8%B7%AF%E4%BA%BA%E7%94%B2's gravatar image

路人甲
131576638836

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link: [text](http://url.com/ "title")
  • image: ![alt](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×881
×91

question asked: 01 Aug, 16:21

question was seen: 132 times

last updated: 01 Aug, 16:21

powered by O*S*Q*A

粤ICP备14040061号-1