You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My requirement is to show horizontally grouped stacked bar chart plotted with the date values. For this, I customized horizontal bar chart example to show grouped horizontally stacked bar chart.
Fig 1)
for i in 0..<models.count {
let variant = self.models![i]
let designValues = self.getDesignData(forModel: variant) //returns TimeInterval in an array
let designEntry = BarChartDataEntry(x: Double(i), yValues: designValues)
dataEntries.append(designEntry)
let prodValues = self.getProductionData(forModel: variant) //returns TimeInterval in an array
let prodEntry = BarChartDataEntry(x: Double(i), yValues: prodValues)
dataEntries1.append(rdEntry)
}
let dateValueFormatter = DateFormatter()
dateValueFormatter.dateFormat = "MMM YYYY"
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Design")
chartDataSet.axisDependency = .right
chartDataSet.valueFormatter = DateValueFormatter(dateFormatter: dateValueFormatter)
let chartDataSet1 = BarChartDataSet(values: dataEntries1, label: "Production")
chartDataSet1.valueTextColor = UIColor.clear
chartDataSet1.axisDependency = .right
chartDataSet1.valueFormatter = DateValueFormatter(dateFormatter: dateValueFormatter)
let dataSets: [BarChartDataSet] = [chartDataSet,chartDataSet1]
chartDataSet.colors = [ChartColorTemplates.material()[0], ChartColorTemplates.material()[1]]
chartDataSet1.colors = [UIColor(red: 230/255, green: 126/255, blue: 34/255, alpha: 1), ChartColorTemplates.material()[2]]
let chartData = BarChartData(dataSets: dataSets)
chartView.data = chartData
let groupSpace = 0.25
let barSpace = 0.05
// (0.3 + 0.05) * 2 + 0.3 = 1.00 -> interval per "group"
chartData.barWidth = barWidth;
chartData.groupBars(fromX: 0.0, groupSpace: groupSpace, barSpace: barSpace)
chartView.notifyDataSetChanged()
chartView.data = chartData
//background color
chartView.backgroundColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1)
//chart animation
chartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .linear)
What did you expect to happen?
When I add the date values (TimeInterval), the date should be stacked properly with respect to the axis dependency and I should able to see the correct values plotted on the stacked bar chart. The expected bar chart should be something like this.
Fig 2)
Note: I added custom logic in stringForValue: method in dateformatter to show the date values with respect to the bar chart (above fig). But it is not working when I zoom.
What happened instead?
When I try to use the date values (date range are between 2016 and 2019) to plot the stacked bar chart, the values are getting added to the previous values while displaying the bar chart. Hence the date range is going till year 2286 (see below fig.). So I calculated the difference between date values and plotted the bar chart. Now I am able to show the bars between the date range. But the values indicated in the bar chart is displaying date values from 1970. (see fig 1)
How can I show the correct date values with respect to the bar chart. Also When I am trying to tap on the second or third stack in the bar, the first stack of the bar is getting clicked.
The text was updated successfully, but these errors were encountered:
blulion
changed the title
Is it possible to show date values in the Stacked BarChart
Is it possible to show date values in the Stacked BarChart?
Apr 18, 2018
What did you do?
My requirement is to show horizontally grouped stacked bar chart plotted with the date values. For this, I customized horizontal bar chart example to show grouped horizontally stacked bar chart.
Fig 1)
What did you expect to happen?
When I add the date values (TimeInterval), the date should be stacked properly with respect to the axis dependency and I should able to see the correct values plotted on the stacked bar chart. The expected bar chart should be something like this.
Fig 2)
Note: I added custom logic in
stringForValue:
method in dateformatter to show the date values with respect to the bar chart (above fig). But it is not working when I zoom.What happened instead?
When I try to use the date values (date range are between 2016 and 2019) to plot the stacked bar chart, the values are getting added to the previous values while displaying the bar chart. Hence the date range is going till year 2286 (see below fig.). So I calculated the difference between date values and plotted the bar chart. Now I am able to show the bars between the date range. But the values indicated in the bar chart is displaying date values from 1970. (see fig 1)
How can I show the correct date values with respect to the bar chart. Also When I am trying to tap on the second or third stack in the bar, the first stack of the bar is getting clicked.
Charts Environment
**Charts version/Branch/Commit Number: 3.0.5
**Xcode version: 9.2
**Swift version: 4.1
**Platform(s) running Charts: iOS
**macOS version running Xcode: 10.12.6
The text was updated successfully, but these errors were encountered: