Hi...
I am having a problem which I can't figure out the answer to...
If I have a chart which I initially view (I use the OnLoaded event to fire the rendering of the chart), I initially will have no data shown, which means, when I do, I leave the ViewXY.Margins to be calculated automatically. When I select data to display, I then manually calculate all margins (left, right, bottom, top) because I have to insert a legend box... as far as I know, I have to calculate all margins for this case, which I am attempting to do. As long as I initially am looking at the chart and select data, everything looks fine, as below:
No data, initial... viewing chart BEFORE selecting data:
[img]
[/img]
Selecting data to show while chart is showing (everything works fine)
[img]
[/img]
However, if I have selected data to plot, then switch to another chart, which I haven't had open yet, for some reason, the axis tick marks are ont he opposite side of the axis... from this point on, no matter what I do, I cannot seem to move the tick marks over to the other side...
Data is selected to show already, THEN viewing the chart:
[img]
[/img]
It would be helpful if I could get an answer to this, as I have been struggling with how to best deal with the legend box for quite some time... we initially were using our own control, but, unfortunately have to move back to the built in control because the built in control won't save in the file when doing Chart.SaveToFile, which is why we are having to move back to this one for now...
Thanks
--Chris
Axis Information Is On Opposite Side
Moderator: Queue Moderators
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Axis Information Is On Opposite Side
This way chart resizes its margins based on legend box height and it also takes the axis space into account
In chart initialization phase:
Sorry code is for Winforms but is almost similar to WPF.
To move the axis ticks to the left, set yAxis.MajorDivTickStyle.Alignment = Near. You most likely have now 'Far' there.
In chart initialization phase:
Code: Select all
m_chart.ViewXY.LegendBox.Visible = true;
m_chart.ViewXY.LegendBox.Position = LegendBoxPosition.BottomCenter;
m_chart.ViewXY.LegendBox.Offset.SetValues(0, 0);
m_chart.ViewXY.AxisLayout.AutoAdjustMargins = false;
m_chart.AfterRendering += m_chart_AfterRendering;
private RectangleXY m_prevRect;
void m_chart_AfterRendering(object sender, AfterRenderingEventArgs e)
{
RectangleXY r = m_chart.ViewXY.LegendBox.GetRenderedRect();
if (r.Width != m_prevRect.Width || r.Height != m_prevRect.Height)
{
m_prevRect = r;
m_chart.AfterRendering -=m_chart_AfterRendering;
RectangleXY rAxis = m_chart.ViewXY.XAxes[0].GetActiveAxisArea();
int iAxisTitleHeight = m_chart.MeasureText(m_chart.ViewXY.XAxes[0].Title.Text, m_chart.ViewXY.XAxes[0].Title.Font).Y;
m_chart.ViewXY.Margins = new System.Windows.Forms.Padding(m_chart.ViewXY.Margins.Left, m_chart.ViewXY.Margins.Top, m_chart.ViewXY.Margins.Right, r.Height + rAxis.Height + iAxisTitleHeight);
m_chart.AfterRendering += m_chart_AfterRendering;
}
}
To move the axis ticks to the left, set yAxis.MajorDivTickStyle.Alignment = Near. You most likely have now 'Far' there.
LightningChart Support Team, PT
-
- Posts: 43
- Joined: Mon Oct 19, 2015 2:50 am
Re: Axis Information Is On Opposite Side
Ahhhh... ok, I see... the AfterRendering here is the key... sometimes i was getting 0 back for the rendering rectangle, and I was, for now, calling all my methods a second time to get this to happen... ok, now that I know about this, this might help in other cases where I sometimes see values as 0 even after i've called things like EndUpdate(), ForceRepaint(), etc...
Thanks for the setting information... I didn't even realize these were settings because this didn't happen all the time
... now that i set these I no longer see the issue... I will give this another try... thanks for the help! ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Thanks for the setting information... I didn't even realize these were settings because this didn't happen all the time
![Embarrassed :oops:](./images/smilies/icon_redface.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
-
- Posts: 43
- Joined: Mon Oct 19, 2015 2:50 am
Re: Axis Information Is On Opposite Side
So I'm still having trouble and confusion....
For some reason, in one chart, when I have the title on HorizontalAlign = Left, and setting a negative distance, it is moving the title to the left... on another chart it is moving it to the right...
I've verified with the debugger that both axis titles are aligned on the left, yet one is going in one direction, while the other is going in the opposite direction...
Correct direction:
[img] [/img]
Wrong direction:
[img] [/img]
Here is the code where I am doing this:
Here is the xaml code where I am setting the title's horizontal alignment
For some reason, in one chart, when I have the title on HorizontalAlign = Left, and setting a negative distance, it is moving the title to the left... on another chart it is moving it to the right...
I've verified with the debugger that both axis titles are aligned on the left, yet one is going in one direction, while the other is going in the opposite direction...
Correct direction:
[img] [/img]
Wrong direction:
[img] [/img]
Here is the code where I am doing this:
Code: Select all
// Move negatively (left/down) for primary y axis or x axis
if(whichAxis == AxisChoices.PrimaryYAxis || whichAxis == AxisChoices.XAxis)
result = -((int)(measure + currentMargin));
// For secondary y axis, move to the right (positive)
// In this case, don't include the size of the string
if (whichAxis == AxisChoices.SecondaryYAxis)
result = (int) (currentMargin);
Here is the xaml code where I am setting the title's horizontal alignment
Code: Select all
<lcu:AxisY.Titlle>
<lcu:AxisYTitle
Angle="90"
HorizontalAlign="Left"
Color="{StaticResource ChartTitleTextColor}"
MouseInteraction="False">
-
- Posts: 43
- Joined: Mon Oct 19, 2015 2:50 am
Re: Axis Information Is On Opposite Side
So it appears I have found a workaround.. I need to set the title's alignment to the right, followed by setting it immediately to the left, in order for things to work... If I just set it to the left, it doesn't align properly... but at least I think at this point i have something that works.... :/