Charts icon indicating copy to clipboard operation
Charts copied to clipboard

CandleStick Charts not resizing properly

Open mikeKane opened this issue 7 years ago • 7 comments

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

mikeKane avatar Feb 19 '18 15:02 mikeKane

are you able to debug a little?

liuxuan30 avatar Feb 20 '18 01:02 liuxuan30

Sure. What would you like to see?

mikeKane avatar Feb 20 '18 19:02 mikeKane

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.

liuxuan30 avatar Feb 21 '18 01:02 liuxuan30

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()

mikeKane avatar Feb 21 '18 14:02 mikeKane

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

liuxuan30 avatar Feb 22 '18 01:02 liuxuan30

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

mikeKane avatar Feb 23 '18 17:02 mikeKane

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

k1ran-ak avatar Mar 24 '22 10:03 k1ran-ak