精华内容
下载资源
问答
  • Line Chart

    2015-04-28 22:07:11
    LineChart
  • I'm using a line chart with JavaFX:LineChart lineChart = new LineChart<>(xAxis, yAxis);XYChart.Series series = new XYChart.Series();lineChart.getData().add(series);I want to add data to the seri...

    I'm using a line chart with JavaFX:

    LineChart lineChart = new LineChart<>(xAxis, yAxis);

    XYChart.Series series = new XYChart.Series();

    lineChart.getData().add(series);

    I want to add data to the series successively, thereby the order in which the values arrive can not be predicted. For example, the index can be between 0 and the current size of the series.

    series.getData().add(new XYChart.Data(index, value));

    Consider the following scenario:

    //initializing...

    series.getData().add(new XYChart.Data(1, 400));

    series.getData().add(new XYChart.Data(3, 500));

    series.getData().add(new XYChart.Data(8, 100));

    series.getData().add(new XYChart.Data(12, 120));

    series.getData().add(new XYChart.Data(20, 300));

    //later...

    series.getData().add(new XYChart.Data(2, 450));

    series.getData().add(new XYChart.Data(5, 300));

    series.getData().add(new XYChart.Data(15, 200));

    The problem is how the graph is depicted. In the example above, at index 20 the graph makes a loop back to index 2. It looks like this:

    Wc0oI.png

    But I want it to look like this:

    7oCkq.png

    What settings are necessary to update the graph properly without additional lines crossing the graph?

    解决方案

    There is a new answer to this problem with JavaFX 9.

    If you have JDK9, try

    lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.X_AXIS);

    (this is the default setting for JavaFX 9)

    If you want for data to be plotted in the order it was added use:

    lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.NONE);

    展开全文
  • Linechart-Barchart-源码

    2021-03-18 07:21:59
    Linechart-Barchart
  • C# WPF画LineChart

    2021-09-23 09:57:59
    自制LineChart
  • flex LineChart

    2014-10-23 09:31:24
    以下是我最近做flex组件编程时的总结,是主要针对lineChart的用法,其中某些属性对同是有横纵坐标的columnChart、barChart等都有效,比如对背景的网格线、横纵坐标线条的粗细颜色和标签的设置都有效。
  • flex_linechart

    2013-05-03 09:28:13
    flex项目开发过程中的动态linechart,主要是曲线可以增量的刷新,纵坐标、刷新频率可以调整,也可以稍微改下根据配置进行曲线设置,这个是少了获取数据的方法用随机数代替,项目中用到动态linechart的可以参考。
  • KLineChart.zip

    2020-08-05 08:57:42
    KLineChart,Android仿火币K线图实现(包含MA,BOLL,MACD,KDJ,RSI,WR指标),博客附件,效果请查看博客相对应项目。
  • Smobiler实现linechart(即线状图)源码
  • 自己写的LineChart有一些基本功能供大家参考
  • Android MPAndroidChart LineChart 首先添加依赖 在project下打开build.gradle,在allprojects写入 maven{ url ‘https://jitpack.io’} 在app下打开build.gradle,添加依赖 implementation ...

    Android MPAndroidChart LineChart

    1. 首先添加依赖

      在project下打开build.gradle,在allprojects写入
      maven{ url ‘https://jitpack.io’}

    在这里插入图片描述

    1. 在app下打开build.gradle,添加依赖

      implementation ‘com.github.PhilJay:MPAndroidChart:v3.1.0’

    在这里插入图片描述
    接下来就可以使用

    在需要的xml中使用对应控件

    控件作用
    com.github.mikephil.charting.charts.BarChart柱状图
    com.github.mikephil.charting.charts.HorizontalBarChart水平柱状图
    com.github.mikephil.charting.charts.LineChart折线图
    com.github.mikephil.charting.charts.PieChart饼图
    com.github.mikephil.charting.charts.CombinedChart组合图
    com.github.mikephil.charting.charts.RadarChart雷达图
    com.github.mikephil.charting.charts.BubbleChart泡泡图
    com.github.mikephil.charting.charts.ScatterChart散点图
    com.github.mikephil.charting.charts.CandleStickChart蜡烛图

    一些通用的方法

    常用方法解释
    setExtraOffsets()设置左,上,右,下的偏移量
    invalidate()加载
    getXAxis()获得x轴
    getAxisRight()获取右轴
    getAxisLeft()获取左轴
    getDescription()获得图表的描述
    getLegend()获得图例的描述

    下面已图为例

    折线图

    1. 设置各点的数据(Entry)
      注意Entry为这个jar包提供的
    List<Entry> yVals1 = new ArrayList<>();
    float[] ys1 = new float[] {
            19f, 19f, 18f, 18f, 18f, 18f, 17f, 16f, 17f, 19f,
            21f, 21f};
    for (int i = 0; i < ys1.length; i++) {
        yVals1.add(new Entry((i + 1) * 3,ys1[i]));
    }
    
    
    1. 用LineDataSet连接各个点的数据
    LineDataSet set1=new LineDataSet(yVals1,"图例名");
    

    为该图例装饰的一些常用方法

    常用方法解释
    setDrawFilled()设置允许填充
    setFillColor()设置填充颜色
    setColor()设置线条颜色
    setMode()设置风格
    setLineWidth()设置线宽
    setHighlightEnabled()是否禁用点击高亮线
    setForm()/设置图例的形式
    setValueTextSize()设置显示值文字大小
    1. 用LineData完成设置
    LineData lineData=new LineData(set1);
    

    多条线可添加在该构造方法后

    LineData lineData=new LineData(set1,set2);
    

    也可以

    ArrayList<ILineDataSet> dataSets=new ArrayList<>();
    dataSets.add(set1);dataSets.add(set2);
    LineData data=new LineData(dataSets);
    
    1. 添加加载
    lineChart.setData(lineData);
    lineChart.invalidate();
    
    1. 设置x轴
    XAxis xAxis = lineChart.getXAxis();
    
    常用方法解释
    setDrawGridLines()是否画网格线
    setAxisMinimum()设置最小值
    setAxisMaximum()最大值
    setLabelCount()显示的个数
    setPosition()所在位置
    setEnabled()禁用显示
    1. 设置左,右轴
      同理x轴
    YAxis axisLeft = lineChart.getAxisLeft();
    

    完整代码

    package com.example.mpandroidchart_all.FragmentChart;
    
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    import androidx.annotation.NonNull;
    import androidx.annotation.Nullable;
    import androidx.fragment.app.Fragment;
    
    import com.example.mpandroidchart_all.Market.TMarket;
    import com.example.mpandroidchart_all.R;
    import com.github.mikephil.charting.charts.LineChart;
    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 java.util.ArrayList;
    import java.util.List;
    
    
    public class lineChartFragment extends Fragment {
        private LineChart lineChart;
        @Nullable
        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View view=inflater.inflate(R.layout.fragment_linechart,container,false);
            lineChart=view.findViewById(R.id.line_chart);
    
            setXAxis();
            setYAxis();
            initData();
    
            return view;
        }
        private void setXAxis(){
            XAxis xAxis = lineChart.getXAxis();
            xAxis.setAxisMinimum(0f);
            xAxis.setAxisMaximum(42f);
            xAxis.setLabelCount(15);
            xAxis.setDrawGridLines(false);
            xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    
        }
        private void setYAxis(){
            YAxis axisLeft = lineChart.getAxisLeft();
            axisLeft.setAxisMaximum(26);
            axisLeft.setAxisMinimum(14);
            lineChart.getAxisRight().setEnabled(false);
        }
    
        private void initData() {
            lineChart.setExtraOffsets(24f,24f,24f,0f);
            setChartData();
        }
        private void setChartData(){
            List<Entry> yVals1 = new ArrayList<>();
            float[] ys1 = new float[] {
                    19f, 19f, 18f, 18f, 18f, 18f, 17f, 16f, 17f, 19f,
                    21f, 21f};
            for (int i = 0; i < ys1.length; i++) {
                yVals1.add(new Entry((i + 1) * 3,ys1[i]));
            }
            LineDataSet set1=new LineDataSet(yVals1,"");
            set1.setDrawFilled(true);
            set1.setFillColor(Color.WHITE);
            LineData lineData=new LineData(set1);
            TMarket tMarket=new TMarket();
            lineChart.setMarker(tMarket);
            lineChart.setData(lineData);
            lineChart.invalidate();
        }
    }
    

    注意我是用碎片做的,如果需要复制所需代码即可

    在这里插入图片描述

    如果想把线改成贝塞斯曲线

    set1.setMode(LineDataSet.Mode.CUBIC_BEZIER)
    

    即可

    展开全文
  • 实现了折线图的实时动态更新,可以自定义X轴坐标,可是设置Y坐标的最大值和最小值,android 绘制折线图(AChartEngine)Linechart 动态更新横轴为获取的当前时间
  • 主要为大家详细介绍了Android LineChart绘制多条曲线的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • LineChart 使用

    千次阅读 2013-08-31 14:20:52
    LineChart 实现2个Y轴不同单位  

    LineChart 实现2个Y轴不同单位

     

    <mx:LineChart id="roomChart" dataProvider="{chartDataList}" showDataTips="true" width="90%" top="40" horizontalCenter="0" fontSize="14">
                <mx:horizontalAxis>
                    <mx:CategoryAxis id="hor" categoryField="updateTime" title="时间" padding="0.5"/>
                </mx:horizontalAxis>
                
                <mx:horizontalAxisRenderers>
                    <mx:AxisRenderer axis="{hor}" canDropLabels="true"/>
                </mx:horizontalAxisRenderers>
                
                <mx:verticalAxisRenderers>
                    <mx:AxisRenderer placement="left" axis="{v1}"/>
                    <mx:AxisRenderer placement="right" axis="{v2}"/>
                </mx:verticalAxisRenderers>
                
                <mx:series>
                    <mx:LineSeries yField="tempData" displayName="时间/温度(℃)" horizontalAxis="{hor}">
                        <mx:verticalAxis>
                            <mx:LinearAxis id="v1" title="温度" baseAtZero="false" maximum="40" minimum="-10"/>
                        </mx:verticalAxis>
                    </mx:LineSeries>
                    
                    <mx:LineSeries yField="humiData" displayName="时间/湿度(%)" horizontalAxis="{hor}">
                        <mx:verticalAxis>
                            <mx:LinearAxis id="v2" title="湿度" baseAtZero="true" maximum="100" minimum="0"/>
                        </mx:verticalAxis>
                    </mx:LineSeries>
                </mx:series>
    
    </mx:LineChart>
    ------------------------------
    对象数组,里面的对象是:
    public var updateTime:String;
    public var tempData:String;
    public var humiData:String;

     

    flex使用lineChart和DateTimeAxis实现时序图

    <?xml version="1.0"?>
    <!-- Simple example to demonstrate the DateTimeAxis class. -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    
        <mx:Script>
            <!--[CDATA[
    
                import mx.collections.ArrayCollection;
    
                [Bindable] 
                public var stockDataAC:ArrayCollection = new ArrayCollection( [
                    {date: "2005, 1, 27", close: 41.71, next: 41.71},
                    {date: "2005, 2, 28", close: 42.21, next: 42.71},
                    {date: "2005, 3, 29", close: 42.11, next: 43.71},
                    {date: "2005, 4, 1", close: 42.71, next: 44.71},
                    {date: "2005, 5, 2", close: 42.99, next: 45.71},
                    {date: "2005, 6, 3", close: 44,    next: 47.71},
                    {date: "2005, 6, 27", close: 41.71, next: 41.71},
                    {date: "2005, 7, 28", close: 42.21, next: 42.71},
                    {date: "2005, 8, 29", close: 42.11, next: 43.71},
                    {date: "2005, 10, 1", close: 42.71, next: 44.71},
                    {date: "2005, 11, 2", close: 42.99, next: 45.71},
                    {date: "2005, 12, 3", close: 44,    next: 47.71} ,
                    {date: "2006, 1, 27", close: 41.71, next: 41.71},
                    {date: "2006, 2, 28", close: 42.21, next: 42.71},
                    {date: "2006, 3, 29", close: 42.11, next: 43.71},
                    {date: "2006, 4, 1", close: 42.71, next: 44.71},
                    {date: "2006, 5, 2", close: 42.99, next: 45.71},
                    {date: "2006, 6, 3", close: 44,    next: 47.71},
                    {date: "2006, 6, 27", close: 41.71, next: 41.71},
                    {date: "2006, 7, 28", close: 42.21, next: 42.71},
                    {date: "2006, 8, 29", close: 42.11, next: 43.71},
                    {date: "2006, 10, 1", close: 42.71, next: 44.71},
                    {date: "2006, 11, 2", close: 42.99, next: 45.71},
                    {date: "2006, 12, 3", close: 44, next: 47.71} ]);
        
                public function myParseFunction(s:String):Date { 
                    // Get an array of Strings from the comma-separated String passed in.
                    var a:Array = s.split(",");
                    // Create the new Date object. Subtract one from 
                    // the month property because months are zero-based in 
                    // the Date constructor.
                    var newDate:Date = new Date(a[0],a[1]-1,a[2]);
                    return newDate;
                }
            ]]-->
        </mx:Script>
    
        <mx:Panel title="DateTimeAxis Example" height="100%" width="100%">
        
            <mx:LineChart id="mychart" height="100%" width="100%"
                paddingRight="5" paddingLeft="5" 
                showDataTips="true"  dataProvider="{stockDataAC}" >
                
                <mx:horizontalAxis>
                    <mx:DateTimeAxis dataUnits="days" parseFunction="myParseFunction"/>  //时序图的时间设置
                </mx:horizontalAxis>
    
                <mx:verticalAxis>
                    <mx:LinearAxis baseAtZero="false" />
                </mx:verticalAxis>
    
                <mx:series>
                    <mx:LineSeries yField="close" xField="date" displayName="AAPL"/>
                     <mx:LineSeries yField="next" xField="date" displayName="BBPL"/>
                </mx:series>
            </mx:LineChart>
            
        </mx:Panel>
    </mx:Application>

    效果如图

    flex时序图

     

     

    效果如图

    flex时序图

     

     

     

    flex的LineChart中怎样设置线条的粗细和颜色

    定义笔触(颜色和粗细) 
    <mx:Stroke id = "s1" color="blue" weight="2"/> 

    定义填充 
    <mx:SolidColor id="sc1" color="blue" alpha=".3"/> 

    使用笔触 
    <mx:LineSeries yField="Profit" form="curve" displayName="Profit" lineStroke="{s1}"/> 

    使用笔触和填充 
    <mx:AreaSeries yField="Profit" form="curve" displayName="Profit" areaStroke="{s1}" areaFill="{sc1}"/> 

    一个LineChart的完全例子,使用了3种笔触和填充,摘自http://www.airia.cn/FLEX4API/livedocs/ 

    Xml代码   收藏代码
    1. <?xml version="1.0"?>  
    2. <!-- Simple example to demonstrate the LineChart and AreaChart controls. -->  
    3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">  
    4.   
    5.     <mx:Script>  
    6.         <![CDATA[ 
    7.  
    8.         import mx.collections.ArrayCollection; 
    9.  
    10.         [Bindable] 
    11.         private var expensesAC:ArrayCollection = new ArrayCollection( [ 
    12.             { Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450 }, 
    13.             { Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 }, 
    14.             { Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300 }, 
    15.             { Month: "Apr", Profit: 1800, Expenses: 1200, Amount: 900 }, 
    16.             { Month: "May", Profit: 2400, Expenses: 575, Amount: 500 } ]); 
    17.         ]]>  
    18.     </mx:Script>  
    19.   
    20.     <!-- Define custom colors for use as fills in the AreaChart control. -->  
    21.     <mx:SolidColor id="sc1" color="blue" alpha=".3"/>  
    22.     <mx:SolidColor id="sc2" color="red" alpha=".3"/>  
    23.     <mx:SolidColor id="sc3" color="green" alpha=".3"/>  
    24.   
    25.     <!-- Define custom Strokes. -->  
    26.     <mx:Stroke id = "s1" color="blue" weight="2"/>  
    27.     <mx:Stroke id = "s2" color="red" weight="2"/>  
    28.     <mx:Stroke id = "s3" color="green" weight="2"/>  
    29.   
    30.     <mx:Panel title="LineChart and AreaChart Controls Example"   
    31.         height="100%" width="100%" layout="horizontal">  
    32.   
    33.         <mx:LineChart id="linechart" height="100%" width="45%"  
    34.             paddingLeft="5" paddingRight="5"   
    35.             showDataTips="true" dataProvider="{expensesAC}">  
    36.                   
    37.             <mx:horizontalAxis>  
    38.                 <mx:CategoryAxis categoryField="Month"/>  
    39.             </mx:horizontalAxis>  
    40.   
    41.             <mx:series>  
    42.                 <mx:LineSeries yField="Profit" form="curve" displayName="Profit" lineStroke="{s1}"/>  
    43.                 <mx:LineSeries yField="Expenses" form="curve" displayName="Expenses" lineStroke="{s2}"/>  
    44.                 <mx:LineSeries yField="Amount" form="curve" displayName="Amount" lineStroke="{s3}"/>  
    45.             </mx:series>  
    46.         </mx:LineChart>  
    47.   
    48.         <mx:Legend dataProvider="{linechart}"/>  
    49.   
    50.         <mx:AreaChart id="Areachart" height="100%" width="45%"  
    51.              paddingLeft="5" paddingRight="5"   
    52.              showDataTips="true" dataProvider="{expensesAC}">  
    53.                    
    54.             <mx:horizontalAxis>  
    55.                 <mx:CategoryAxis categoryField="Month"/>  
    56.             </mx:horizontalAxis>  
    57.   
    58.             <mx:series>  
    59.                 <mx:AreaSeries yField="Profit" form="curve" displayName="Profit" areaStroke="{s1}" areaFill="{sc1}"/>  
    60.                 <mx:AreaSeries yField="Expenses" form="curve" displayName="Expenses" areaStroke="{s2}" areaFill="{sc2}"/>  
    61.                 <mx:AreaSeries yField="Amount" form="curve" displayName="Amount" areaStroke="{s3}" areaFill="{sc3}"/>  
    62.             </mx:series>  
    63.         </mx:AreaChart>  
    64.               
    65.         <mx:Legend dataProvider="{Areachart}"/>  
    66.   
    67.     </mx:Panel>  
    68. </mx:Application>  

     

    Flex中如何通过lineStroke样式改变LineChart图表线条颜色的例子

    http://blog.minidx.com/2008/11/23/1644.html



    当DateTimeAxis的labelUnits属性为months时,用Flex 4编译,标签会按日期降序显示,用Flex 3编译则没有这个问题。这是Flex 4的Bug,见http://bugs.adobe.com/jira/browse/FLEXDMV-2344

    在Flex 4中,DateTimeAxis的父类NumericAxis增加了一个属性:direction,这使得DateTimeAxis标签可以按日期升序或降序显示。

    但此处不能用direction解决这个Bug,得覆写DateTimeAxis是的的buildLabelCache()方法,或是设置disabledDays或disabledRanges属性。

    displayLocalTime="true"   解决日期不对



    展开全文
  • 使用LineChart,显示多条曲线
  • 首先声明,此自定义LineChart并非本人定义,而是在他人(io.github.kntryer.linechart)基础上修改的,因原来的LineChart如果点只有两三个的时候会超出边界,我修改之后则不会再出现这种情况。 同时我给折线图添加了...

        首先声明,此自定义LineChart并非本人定义,而是在他人(io.github.kntryer.linechart)基础上修改的,因原来的LineChart如果点只有两三个点的时候折线会超出下边界,我修改之后则不会再出现这种情况。 同时我给折线图添加了上下padding使图标更加美观。看效果。

    
    
    LineChart.java:
    public class LineChart extends View {
    
        private int mWidth, mHeight;//View 的宽和高
    
        private float mFontSize = 12;//字体的大小
        private float mStrokeWidth = 1.5f;//线条的宽度
        private float mPointRadius = 2;//点的半径
        private int mDateTextColor = Color.parseColor("#cfcfcf");//日期字体颜色
        private int mDarkColor = Color.parseColor("#5b7fdf");//点、线的颜色(深色)
        private int mLightColor = Color.parseColor("#d5d8f7");//点、线的颜色(浅色)
        private int mShapeColor = Color.parseColor("#f3f6fd");//阴影的颜色
    
        private String[] mXItems;//X轴的文字
        private int[] mPoints;//点的数组,-1表示该日还没到
        private int mLength = 7;//最大比例
    
        private Paint mDatePaint = new Paint();//日期画笔
        private Paint mPointPaint = new Paint();//点画笔
        private Paint mLinePaint = new Paint();//线条画笔
        private Paint mShapePaint = new Paint();//阴影部分画笔
    
        private int max = 7;
        private Context mContext;
    
        public LineChart(Context context) {
            this(context, null);
        }
    
        public LineChart(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }
    
        public LineChart(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            mContext = context;
            TypedArray typedArray = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.LineChart, 0, 0);
            try {
                mDateTextColor = typedArray.getColor(R.styleable.LineChart_DateTextColor, mDateTextColor);
                mDarkColor = typedArray.getColor(R.styleable.LineChart_DarkColor, mDarkColor);
                mLightColor = typedArray.getColor(R.styleable.LineChart_LightColor, mLightColor);
                mShapeColor = typedArray.getColor(R.styleable.LineChart_ShapeColor, mShapeColor);
                mFontSize = typedArray.getDimensionPixelSize(R.styleable.LineChart_FontSize,
                        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mFontSize, mContext.getResources().getDisplayMetrics()));
                mStrokeWidth = typedArray.getDimensionPixelSize(R.styleable.LineChart_StrokeWidth,
                        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mStrokeWidth, mContext.getResources().getDisplayMetrics()));
                mPointRadius = typedArray.getDimensionPixelSize(R.styleable.LineChart_PointRadius,
                        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mPointRadius, mContext.getResources().getDisplayMetrics()));
            } finally {
                typedArray.recycle();
            }
    
            initPaint();
        }
    
        private void initPaint() {
            //日期画笔
            mDatePaint.setTextSize(mFontSize);
            mDatePaint.setColor(mDateTextColor);
            //点画笔
            mPointPaint.setTextSize(mFontSize);
            mPointPaint.setColor(mDarkColor);
            //线画笔
            mLinePaint.setAntiAlias(true);
            mLinePaint.setStrokeWidth(mStrokeWidth);//设置线条宽度
            mLinePaint.setStyle(Paint.Style.FILL);
            mLinePaint.setColor(mDarkColor);
            //阴影部分画笔
            mShapePaint.setAntiAlias(true);
            mShapePaint.setStyle(Paint.Style.FILL);
            mShapePaint.setColor(mShapeColor);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthMode = MeasureSpec.getMode(widthMeasureSpec);
            int heightMode = MeasureSpec.getMode(heightMeasureSpec);
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            mWidth = widthSize;
            mHeight = heightSize;
            if (heightMode == MeasureSpec.AT_MOST) {
                mHeight = mWidth / 7 * 7;
            }
            setMeasuredDimension(mWidth, mHeight);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
    
            if (mXItems == null) {
                mXItems = new String[]{"", "", "", "", "", "", ""};
                mPoints = new int[]{0, -1, -1, -1, -1, -1, -1};
                mLength = mXItems.length;
            }
    
            //最大比例
            for (int i = 0; i < mLength; i++) {
                if (mPoints[i] > max) {
                    max = mPoints[i];
                }
            }
            //原点坐标
            int xOrigin = (int) (0.25 * mWidth / mLength);
            int yOrigin = (int) (mHeight - 3 * mFontSize);
            // X        canvas.drawLine(xOrigin, yOrigin, mWidth - xOrigin, yOrigin, mLinePaint);
            Path xpath = new Path();
            xpath.moveTo(mWidth - xOrigin - mFontSize / 3, yOrigin + mFontSize / 3);
            xpath.lineTo(mWidth - xOrigin, yOrigin);
            xpath.lineTo(mWidth - xOrigin - mFontSize / 3, yOrigin - mFontSize / 3);
            xpath.close();
            canvas.drawPath(xpath, mLinePaint);
            // Y        canvas.drawLine(xOrigin, yOrigin, xOrigin, mFontSize, mLinePaint);
            Path ypath = new Path();
            ypath.moveTo(xOrigin - mFontSize / 3, mFontSize + mFontSize / 3);
            ypath.lineTo(xOrigin, mFontSize);
            ypath.lineTo(xOrigin + mFontSize / 3, mFontSize + mFontSize / 3);
            ypath.close();
            canvas.drawPath(ypath, mLinePaint);
    
    
            int[] xPoints = new int[mLength];//x轴的刻度集合
            int[] yPoints = new int[mLength];//y轴的刻度集合
    
            for (int i = 0; i < mLength; i++) {
                //获取点的坐标
                xPoints[i] = (int) ((i + 0.5) * (mWidth / mLength));
                yPoints[i] = (int) ((max - (mPoints[i] == -1 ? 0 : mPoints[i])) * ((mHeight - 6 * mFontSize) / max));
    
                if (i > 0) {
                    //画一个实心梯形,阴影部分
                    Path path = new Path();
                    path.moveTo(xPoints[i - 1], yOrigin - mStrokeWidth);
                    path.lineTo(xPoints[i - 1], yPoints[i - 1] + 3 * mFontSize - mStrokeWidth);
                    path.lineTo(xPoints[i], yPoints[i] + 3 * mFontSize - mStrokeWidth);
                    path.lineTo(xPoints[i], yOrigin - mStrokeWidth);
                    path.close();
                    canvas.drawPath(path, mShapePaint);
                }
                //画出日期
                canvas.drawText(mXItems[i], (int) ((i + 0.5) * mWidth / mLength) - mFontSize / 2, mHeight - mFontSize, mDatePaint);
            }
    
            for (int i = 0; i < mLength; i++) {
                if (mPoints[i] == -1) {
                    mLinePaint.setColor(mLightColor);
                    mPointPaint.setColor(mLightColor);
                } else {
                    mLinePaint.setColor(mDarkColor);
                    mPointPaint.setColor(mDarkColor);
                }
                if (i > 0) {
                    //画连线
                    canvas.drawLine(xPoints[i - 1], yPoints[i - 1] + 3 * mFontSize, xPoints[i], yPoints[i] + 3 * mFontSize, mLinePaint);
                }
                //画点的数值
                canvas.drawText(String.valueOf(mPoints[i]).equals("-1") ? " " : String.valueOf(mPoints[i]), xPoints[i] - mFontSize / 2, yPoints[i] + 2 * mFontSize, mPointPaint);
            }
    
            for (int i = 0; i < mLength; i++) {
                if (mPoints[i] == -1) {
                    mLinePaint.setColor(mLightColor);
                    mPointPaint.setColor(mLightColor);
                } else {
                    mLinePaint.setColor(mDarkColor);
                    mPointPaint.setColor(mDarkColor);
                }
                //画点
                if (!(yOrigin ==( 3 * mFontSize + yPoints[i])))
                    canvas.drawCircle(xPoints[i], yPoints[i] + 3 * mFontSize, mPointRadius, mPointPaint);
            }
        }
    
        public void setData(List<LineChartData> dataList) {
            mLength = dataList.size();
            if (mLength > 0) {
                mXItems = new String[mLength];
                mPoints = new int[mLength];
                for (int i = 0; i < mLength; i++) {
                    mPoints[i] = dataList.get(i).getPoint();
                    mXItems[i] = dataList.get(i).getItem();
                }
            }
            invalidate();
        }
    }
    
     
    
    LineChartData.java:
    public class LineChartData {
    
        private int point;
        private String item;
    
        public int getPoint() {
            return point;
        }
    
        public void setPoint(int point) {
            this.point = point;
        }
    
        public String getItem() {
            return item;
        }
    
        public void setItem(String item) {
            this.item = item;
        }
    }
    
    main_activity.xml
    <io.github.kntryer.linechart.LineChart
        android:id="@+id/line_chart_week"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@color/white"
        app:DarkColor="@color/blue_dark"
        app:LightColor="@color/blue"
        app:ShapeColor="@color/blue_light" />
    
    MainActivity.java
    public class MainActivity extends AppCompatActivity {
    
        private LineChart mWeekLineChart;
    
        private String[] mWeekItems = new String[]{"", "", "","","",""};
        private int[] mWeekPoints = new int[]{60, 100, 111,300, 298, -1};
    
    
        private List<LineChartData> dataList1 = new ArrayList<>();
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mWeekLineChart = (LineChart) findViewById(R.id.line_chart_week);
    
            for (int i = 0; i < mWeekItems.length; i++) {
                LineChartData data = new LineChartData();
                data.setItem(mWeekItems[i]);
                data.setPoint(mWeekPoints[i]);
                dataList1.add(data);
            }
            mWeekLineChart.setData(dataList1);
        }
    
    }
        以上只是我个人根据项目需要进行的简单改造,欢迎交流指教。

        源码在这:http://download.csdn.net/detail/qq_32371277/9873522

    展开全文
  • javafx折线图LineChart

    千次阅读 2019-05-03 18:35:07
    代码 public class TestLineChart extends Application { ... private LineChart chart; private NumberAxis xAxis; private NumberAxis yAxis; public static double normalDistribution(double x, ...
  • flex LineChart实例

    2009-12-02 15:14:59
    flex LineChart实例个人项目开发中的一个页面
  • linechart中添加红色Y线,拖动该线的过程中,经过数据点时,会实时更新datagrid中对应的X、Y值数据。
  • KLineChart样本 KLineChart( )示例代码。 包含多个前端框架版本。 跑步 React cd react-sample && npm install && npm run start Vue cd vue-sample && npm install && npm run start 角度的 cd ng-sample && ...
  • fl_animated_linechart 一个动画的图表库,用于抖动。 支持日期时间轴 多个y轴,支持不同的单位 高光选择 图表动画 经过3000多分测试,仍然表现出色 当前有两个不同的图表: 折线图 面积图 入门 尝试示例项目或将...
  • LineChart 一个简单的拆线图
  • Flex BlazeDs 推数据生成lineChart实例 前台生成lineChart 实时监控可作参考
  • LineChart(折线图) 的简单使用

    千次阅读 2020-02-24 00:40:35
    LineChart 的简单使用LineChart依赖代码XMLJAVA代码效果图LineChart 的线的一些简单属性设置我们先来看一下效果图代码如下关于Mode的设置代码效果图 LineChart依赖 首先在app中的dependencies 中复制下面这行依赖 ...
  • 画布线图 安装 npm install --save canvas-linechart
  • LabelRotation LineChart

    2010-06-14 21:02:00
    LabelRotation LineChart
  • Android-LineChart 介绍 一个简单的折线,贝塞尔曲线图表控件,高度可扩展,支持动态显示。 效果图 使用 设置布局 2. 添加数据 ```Java lineChartView.setData(datas); 修改Y轴标尺间隔 lineChartView....
  • LineChart中No chart data available的自定义

    千次阅读 2018-08-17 21:40:25
    LineChart mLineChart = (LineChart) rootView.findViewById(R.id.lineChart); if(recordDataList.size()!=0){  //当数据不为空的时候 for(int i=0;i&lt;recordDataList.size();i++){ mList.add(recordData.....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 42,425
精华内容 16,970
关键字:

linechart