SwiftUICharts
SwiftUICharts copied to clipboard
Q: space for infoBox
How does a LineChart know how much space to leave between the metadata title and the top of the chart for displaying and infoBox when the user taps on the chart?
When I display an infoBox, it throws off the alignment of the axes. The x-axis no longer starts at the bottom of the y-axis and instead is moved part way up on the y-axis.
In my LineChartStyle
I have the following:
infoBoxPlacement: .infoBox(isStatic: false),
infoBoxContentAlignment: .vertical,
infoBoxBorderColour: Color.primary,
infoBoxBorderStyle: StrokeStyle(lineWidth: 1),
The space is set by the view modifier .infoBox(chartData: data, height: 140)
, the default set to 70.
I'm not sure what exactly the issue you're facing is, could you post a screenshot please?
It might be the order of the view modifiers as each one wraps a stack layer around those that come before. .infoBox
should probably be near the end of the chain.
I just noticed a placement issue with with the box, I'll add I PR for it but I don't think its the issue that you are facing.
Here is a screen shot that shows the issue. The value for "Mark" is 10, but notice that the y-axis has shifted down so that the "10.00" y-axis label isn't lined up properly. I believe this happens due to the infoBox height
.
Here is my code that creates the chart:
LineChart(chartData: chartData)
.pointMarkers(chartData: chartData)
.touchOverlay(chartData: chartData, formatter: numberFormatter)
.xAxisLabels(chartData: chartData)
.yAxisLabels(
chartData: chartData,
formatter: numberFormatter,
colourIndicator: .style(size: 12)
)
.headerBox(chartData: chartData)
.legends(
chartData: chartData,
columns: [GridItem(.flexible()), GridItem(.flexible())]
)
.infoBox(chartData: chartData)
.id(UUID())
.frame(
minWidth: 300,
maxWidth: Double.infinity,
minHeight: 300,
idealHeight: 450,
maxHeight: 600,
alignment: .center
)
.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 50))