ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.62k stars 6k forks source link

CandleStick Charts not resizing properly #3273

Open mikeKane opened 6 years ago

mikeKane commented 6 years ago

What I expected:

To add 12 data points and have them size accordingly

What happened:

The CandleStick boxes became the width of the wicks

Explanation:

In my application I am displaying 12 data points with 3 data entries. A total of 36 possible candles could be on the screen at any given time. They are all spaced out evenly with each point based on a range. When displaying 12 points the boxes go from boxes to sticks.

When I trim the number of points down to 7, it displays properly. Is there anyway to keep the ratio the same while adding as many points as we want?

*Notice the orange points

image uploaded from ios img_0699 1

liuxuan30 commented 6 years ago

are you able to debug a little?

mikeKane commented 6 years ago

Sure. What would you like to see?

liuxuan30 commented 6 years ago

The candle stick chart's stick width is dynamicly changing. The more data, the thinner it is. But your image does seem weird, so I need you to debug the candle stick rendering, to see how the width is calculated. Normally, I didn't see such issue reported by other people.

So it could be your mistakes or a bug inside. Need you to look at ChartsDemo.

Are you using addEntry APIs? Have you tried to call out ChartData's notifyDataChanged, and also the Chart view's notifyDataSetChanged?

The idea is when you add new entries, the chart data should recalculate and the chart view needs update too.

mikeKane commented 6 years ago

Here is a snippet of how I am passing the data inside of the chart. I tried to keep it identical to the charts demo. I do not see addEntry maybe I am missing something there, but the demo does not have that either.

func createDataSet(in dataEntry: [CandleChartDataEntry]?, with color: UIColor, space: CGFloat) -> CandleChartDataSet {

        let set = CandleChartDataSet(values: dataEntry, label: "Data Set")

        set.axisDependency = .left
        set.setColor(color)
        set.drawIconsEnabled = false
        set.barSpace = space
        set.shadowColor = color
        set.shadowWidth = 1.0

        set.decreasingColor = color
        set.decreasingFilled = true

        set.increasingColor = color
        set.increasingFilled = false

        set.neutralColor = color

        return set
    }
func createDataSets(in cellEntry: [CandleChartDataEntry]?, wifiEntry: [CandleChartDataEntry]?, vpnEntry: [CandleChartDataEntry]?) -> CandleChartData {
        return CandleChartData(dataSets: [self.createDataSet(in: cellEntry, with: UIColor.pingerBlue(), space: 0.3),
                                          self.createDataSet(in: wifiEntry, with: UIColor.pingerOrange(), space: 0.45),
                                          self.createDataSet(in: vpnEntry, with: UIColor.green, space: 0.3)])
    }
        let data = self.dataManager.createDataSets(in: cellEntry, wifiEntry: wifiEntry, vpnEntry: vpnEntry)
        data.setDrawValues(false)
        self.candleStickChartView.data = data
        self.candleStickChartView.data?.notifyDataChanged()
        self.candleStickChartView.notifyDataSetChanged()
liuxuan30 commented 6 years ago

can I ask you to provide a reproducible code based on ChartsDemo so I can see the issue?

mikeKane commented 6 years ago

After posting this code, it seems the spacing was different on the wifiEntry. After changing that it seems a bit better.

k1ran-ak commented 2 years ago

hey mikeKane instead of taking the x axis values as timestamps try to use the indices of the array for timestamps. later you can change the indices of x axis values to timestamps with Axis formatter