分享

WilliamChart图表库

 一楠tech 2017-11-09

创建一个新的chart需要继承自ChartView的坐标轴,同时实现一些必要的方法。我觉的这些方法足以让你绘制出任何你想要的效果。

xml

  1. <com.db.chart.view.ChartView
  2. xmlns:chart="http://schemas./apk/res-auto"
  3. android:layout_width="match_parent"
  4. android:layout_height="dp"
  5. ...
  6. chart:chart_shadowDx="dp"
  7. chart:chart_shadowDy="dp"
  8. chart:chart_shadowRadius="dp"
  9. chart:chart_shadowColor="color"
  10. chart:chart_fontSize="dp"
  11. chart:chart_typeface="typeface"
  12. chart:chart_axisBorderSpacing="dp"
  13. chart:chart_axisThickness="dp"
  14. chart:chart_axisTopSpacing="dp"
  15. chart:chart_axisColor="color"
  16. chart:chart_axisX="boolean"
  17. chart:chart_label="boolean"
  18. chart:chart_labelColor="color"
  19. />

--

  1. // Customize labels
  2. chart.setLabels(NONE/OUTSIDE/INSIDE)
  3. chart.setLabelColor(color)
  4. chart.setFontSize(integer)
  5. chart.setTypeface(typeface)
  6. // Define grid
  7. chart.setGrid(paint)
  8. chart.setHorizontalGrid(paint)
  9. chart.setVerticalGrid(paint)
  10. // Show threshold line
  11. chart.setThresholdLine(float, paint)
  12. chart.setMaxAxisValue(integer, integer)
  13. chart.setStep(integer)
  14. chart.setTopSpacing(dimen)
  15. chart.setBorderSpacing(dimen)
  16. chart.setAxisX(boolean)
  17. chart.show()
  18. // Update values of a given set
  19. chart.updateValues(int, array)
  20. // Notify chart about updated values
  21. chart.notifyDataUpdate()
  22. // Tooltip support
  23. chart.showTooltip(view)
  24. chart.dismissTooltip(view)

LineChart(跟上面相同的部分用省略号)

  1. <com.db.chart.LineChartView
  2. ...
  3. />

java代码:

  1. LineChartView chartView= new LineChartView()
  2. LineSet lineSet = new LineSet()
  3. lineSet.addPoint(new Point(string, float)
  4. // Style dots
  5. lineSet.setDots(boolean)
  6. lineSet.setDotsColor(color)
  7. lineSet.setDotsRadius(dimen)
  8. lineSet.setDotsStrokeThickness(dimen)
  9. lineSet.setDotsStrokeColor(color)
  10. // Style line
  11. lineSet.setLineThickness(dimen)
  12. lineSet.setLineColor(color)
  13. // Style background fill
  14. lineSet.setFill(boolean)
  15. lineSet.setFillColor(color)
  16. // Style type
  17. lineSet.setDashed(boolean)
  18. lineSet.setSmooth(boolean)
  19. chartView.addData(lineSet)

BarChart & StackBarChart

  1. <com.db.chart.BarChartView
  2. ...
  3. chart:chart_barSpacing="dp"
  4. chart:chart_setSpacing="dp"
  5. />

java代码

  1. BarChartView chartView = new BarcChartView()
  2. barChart.setBarSpacing(dimen)
  3. barChart.setSetSpacing(dimen)
  4. barChart.setBarBackground(boolean)
  5. barChart.setBarBackgroundColor(color)
  6. barChart.setRoundCorners(dimen)
  7. BarSet barSet = new BarSet()
  8. Bar bar = new Bar(string, float)
  9. bar.setColor(color)
  10. barSet.addBar(bar)
  11. chartView.addData(barSet)

Listener的设置

  1. chart.setOnEntryClickListener(new OnEntryClickListener(){
  2. @Override
  3. public void onClick(int setIndex, int entryIndex, Rect entryRect) {
  4. //Do things
  5. }
  6. });

动画

  1. Animation anim = new Animation()
  2. anim.setDuration(integer)
  3. anim.setEasing(easingFunction)
  4. anim.setEndAction(runnable)
  5. // Animation overlap between entries
  6. anim.setOverlap(float)
  7. // Animation starting point
  8. anim.setStartPoint(float, float)
  9. // Include alpha transition
  10. anim.setAlpha(int)
  11. // Starts animation
  12. chart.animate(animation)

实现BaseEasingMethod 接口你可以自定义你自己的动画函数我已经实现了一些:

  • LinearEase

  • BounceEaseOut

  • ElasticEaseOut

  • CircEaseOut

  • CubicEaseOut

  • ExpoEaseOut

  • QuadEaseOut

  • QuartEaseOut

  • QuintEaseOut

  • SineEaseOut


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约