iOS图表反转X轴方向 [英] iOS-charts invert the X axis direction

查看:130
本文介绍了iOS图表反转X轴方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用

这就是我需要的样子:

我的问题

有没有一种方法可以反转x轴?

有没有一种方法可以使图表正确对齐?

以下是我的一些代码,并尝试解决此问题:

  class ViewController:UIViewController {@IBOutlet弱var barChartView:BarChartView!//...func plotChart(){//创建历史记录数据//...barChartView.data = chartData//'chartData'是包含所有历史记录信息的BarChartData()//没有效果barChartView.legend.direction = .RightToLeft//图表折线barChartView.leftAxis.axisMinValue = 30barChartView.leftAxis.axisMaxValue = 0//破坏缩放能力barChartView.setVisibleXRangeMinimum(CGFloat(40))barChartView.setVisibleXRangeMaximum(CGFloat(1))}} 

解决方案

chartLegend.swift 文件中,存在一个变量:

公共变量方向= ChartLegendDirection.LeftToRight

尝试在该文件中进行更改,这可能会解决您的问题.

I have a bar chart built using Daniel Gindi iOS-charts. It represents history data over a period of time. The issue I am having is that the data is being plotted from left-to-right (new data -> old data). I need it to be plotted as right-to-left (old data -> new data). I know that I can reverse the order I input data into BarChartData, but then I have the issue of the chart still being left aligned. It needs to be right aligned. I found a discussion here talking about the issue of inverting the x-axis and how it could be resolved (currently not an included feature of the framework), however I can't figure out what actually needs to be done. Here are examples of what I need:

This is what my chart currently looks like:

This is what I needs it to look like:

My Questions

Is there a way to invert the x-axis?

or

Is there a way to right align the chart?

Here is some of my code and attempts to resolve the issue:

class ViewController: UIViewController {

    @IBOutlet weak var barChartView: BarChartView!

    //...

    func plotChart() {

        // Create history data
        //...

        barChartView.data = chartData  // 'chartData' is the BarChartData() containing all of the history information

        // No efect
        barChartView.legend.direction = .RightToLeft

        // Chart breaks
        barChartView.leftAxis.axisMinValue = 30
        barChartView.leftAxis.axisMaxValue = 0

        // Breaks the ability to zoom
        barChartView.setVisibleXRangeMinimum(CGFloat(40))
        barChartView.setVisibleXRangeMaximum(CGFloat(1))

    }

}

解决方案

In the chartLegend.swift file there is a variable:

public var direction = ChartLegendDirection.LeftToRight

Try to make the change in that file, it might solve your problem.

这篇关于iOS图表反转X轴方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆