Software FX Community

# Y label for line graph

## Recommended Posts

```Hi,
I am drawing a straight horizontal line graph (y = some constant)
The constant is a floating number (example 2.37).
I cann't seem to get the y axis's label to show this value at the "right
spot" (where this line graph is) -- see attachment.
Thanks,
Ming```
##### Share on other sites

```Looks like a rounding problem.
What is the scale in your Y-Axis (Min and Max) ?
If you have a very small scale, the difference between 2.370 and 2.374 may
be big, however the label for both is the same if you are using two decimals
(2.37).
I think what's happening is that the label you are seeing is for 2.37?, make
sure your Min, Max and Step (if you are setting one) are set to values that
are ROUNDED to 2 decimals, otherwise the labels themselves may not be
rounded.
--
www.chartfx.com```
##### Share on other sites

```Here is the code that produces the chart.
I set the MIN and MAX to be the y value plus/minus a constant.
I tried a few combinations but still cann't get the correct label.
Thanks again.
ming
int series = 1;
chart1.OpenData(COD.Values, series, (int)COD.Unknown);
chart1.OpenData(COD.XValues, series, (int)COD.Unknown);
chart1.AxisY.DataFormat.Decimals = 2;
chart1.AxisY.LabelsFormat.Decimals = 2;
double avg = 2.37;
double stddev = .72;
chart1.AxisY.Min = avg - stddev;
chart1.AxisY.Max = avg + stddev;
//chart1.AxisY.Step = stddev;
//chart1.AxisY.MinorStep = stddev;
//chart1.AxisY.FirstLabel = chart1.AxisY.Min;
for (int i = 0; i < series; i++)
{
int count = 2;
double val = avg;
for (int k = 0; k < count; k += 1)
{
chart1.Value[i, k] = val;
chart1.XValue[i, k] = k;
}
}
chart1.CloseData(COD.XValues);
chart1.CloseData(COD.Values);
"SoftwareFX Support" <noreply@softwarefx.com> wrote in message
news:pKKwlxNqFHA.1992@webserver3.softwarefx.com...
> Looks like a rounding problem.
>
> What is the scale in your Y-Axis (Min and Max) ?
>
> If you have a very small scale, the difference between 2.370 and 2.374 may
> be big, however the label for both is the same if you are using two
decimals
> (2.37).
>
> I think what's happening is that the label you are seeing is for 2.37?,
make
> sure your Min, Max and Step (if you are setting one) are set to values
that
> are ROUNDED to 2 decimals, otherwise the labels themselves may not be
> rounded.
>
> --
> www.chartfx.com
>
>```
##### Share on other sites

```Hi again,
did you find anything from the code?
I need to resolve this quickly...
Thanks,
Ming
"SoftwareFX Support" <noreply@softwarefx.com> wrote in message
news:pKKwlxNqFHA.1992@webserver3.softwarefx.com...
> Looks like a rounding problem.
>
> What is the scale in your Y-Axis (Min and Max) ?
>
> If you have a very small scale, the difference between 2.370 and 2.374 may
> be big, however the label for both is the same if you are using two
decimals
> (2.37).
>
> I think what's happening is that the label you are seeing is for 2.37?,
make
> sure your Min, Max and Step (if you are setting one) are set to values
that
> are ROUNDED to 2 decimals, otherwise the labels themselves may not be
> rounded.
>
> --
> www.chartfx.com
>
>```
##### Share on other sites

```(this answer appeared in a different thread, but belongs here, I think):
Ok. The problem is you are adding a String label with the line:
Nowhere you are specifying where this label should go.
The way String labels work in a numeric axis is through the LabelValue
property, this property makes the equivalence between the index of the label
(0 in this case) and the logical value in the axis, these labels are evenly
spaced.
If you want to label an arbitrary value, completely independent of Min/Max
and other Axis labels, the best option for you is a Constant Line.
The following code adds a constant line displaying a label for the value
2.37:
ConstantLine cl = new ConstantLine();
cl.Value = val;
cl.Text = val.ToString();
cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
Use this code INSTEAD of the YLeg code. Note that there is  no guarantee
that this label won't overlap another axis labels. If this is the ONLY label
you want in your axis, you may hide the regular axis labels by doing:
chart1.AxisY.Style |= AxisStyle.HideText;
--
www.chartfx.com```
##### Share on other sites

```Thanks for the repost....
ConstantLine ONLY works when there is other series in the chart.
In my case, I don't have data series.  The line is my data.
Thanks again.
Ming
"Holger Wilken" <holger.wilken@megatel.de> wrote in message
news:wlxzWpkqFHA.1724@webserver3.softwarefx.com...
> (this answer appeared in a different thread, but belongs here, I think):
>
> Ok. The problem is you are adding a String label with the line:
>
>
> Nowhere you are specifying where this label should go.
>
> The way String labels work in a numeric axis is through the LabelValue
> property, this property makes the equivalence between the index of the
label
> (0 in this case) and the logical value in the axis, these labels are
evenly
> spaced.
>
> If you want to label an arbitrary value, completely independent of Min/Max
> and other Axis labels, the best option for you is a Constant Line.
>
> The following code adds a constant line displaying a label for the value
> 2.37:
>
> ConstantLine cl = new ConstantLine();
>
> cl.Value = val;
>
> cl.Text = val.ToString();
>
> cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
>
>
> Use this code INSTEAD of the YLeg code. Note that there is  no guarantee
> that this label won't overlap another axis labels. If this is the ONLY
label
> you want in your axis, you may hide the regular axis labels by doing:
>
> chart1.AxisY.Style |= AxisStyle.HideText;
>
> --
> www.chartfx.com
>
>
>
>```
##### Share on other sites

```I think, I found a way to do this.
I use the CustemSteps property, the label shows exactly where i want it to
be....
"Holger Wilken" <holger.wilken@megatel.de> wrote in message
news:wlxzWpkqFHA.1724@webserver3.softwarefx.com...
> (this answer appeared in a different thread, but belongs here, I think):
>
> Ok. The problem is you are adding a String label with the line:
>
>
> Nowhere you are specifying where this label should go.
>
> The way String labels work in a numeric axis is through the LabelValue
> property, this property makes the equivalence between the index of the
label
> (0 in this case) and the logical value in the axis, these labels are
evenly
> spaced.
>
> If you want to label an arbitrary value, completely independent of Min/Max
> and other Axis labels, the best option for you is a Constant Line.
>
> The following code adds a constant line displaying a label for the value
> 2.37:
>
> ConstantLine cl = new ConstantLine();
>
> cl.Value = val;
>
> cl.Text = val.ToString();
>
> cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
>
>
> Use this code INSTEAD of the YLeg code. Note that there is  no guarantee
> that this label won't overlap another axis labels. If this is the ONLY
label
> you want in your axis, you may hide the regular axis labels by doing:
>
> chart1.AxisY.Style |= AxisStyle.HideText;
>
> --
> www.chartfx.com
>
>
>
>```
##### Share on other sites

```> ConstantLine ONLY works when there is other series in the chart
I don't know what you mean by this.
> In my case, I don't have data series
Yes, you do, you have one data series, otherwise there would be no chart.
You are doing:
chart1.OpenData(COD.Values, series, (int)COD.Unknown);
So you have <series> number of series.
--
www.chartfx.com
"Ming Goi" <mgoi@angoss.com> wrote in message
news:hV5yGNoqFHA.1992@webserver3.softwarefx.com...
> Thanks for the repost....
> ConstantLine ONLY works when there is other series in the chart.
> In my case, I don't have data series.  The line is my data.
> Thanks again.
> Ming
>
> "Holger Wilken" <holger.wilken@megatel.de> wrote in message
> news:wlxzWpkqFHA.1724@webserver3.softwarefx.com...
>> (this answer appeared in a different thread, but belongs here, I think):
>>
>> Ok. The problem is you are adding a String label with the line:
>>
>>
>> Nowhere you are specifying where this label should go.
>>
>> The way String labels work in a numeric axis is through the LabelValue
>> property, this property makes the equivalence between the index of the
> label
>> (0 in this case) and the logical value in the axis, these labels are
> evenly
>> spaced.
>>
>> If you want to label an arbitrary value, completely independent of
>> Min/Max
>> and other Axis labels, the best option for you is a Constant Line.
>>
>> The following code adds a constant line displaying a label for the value
>> 2.37:
>>
>> ConstantLine cl = new ConstantLine();
>>
>> cl.Value = val;
>>
>> cl.Text = val.ToString();
>>
>> cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
>>
>>
>> Use this code INSTEAD of the YLeg code. Note that there is  no guarantee
>> that this label won't overlap another axis labels. If this is the ONLY
> label
>> you want in your axis, you may hide the regular axis labels by doing:
>>
>> chart1.AxisY.Style |= AxisStyle.HideText;
>>
>> --
>> www.chartfx.com
>>
>>
>>
>>
>
>```
##### Share on other sites

```Hi again,
I still have problem.
The CustomSteps seems to work for positive (Min/Max) only.
Please take a look at the attach image.
The blue labels are the ones, I want.
I marked RED X for the ones, I don't want.
If you can give a sample code for this would be great.
Thanks again.
Here is the code that produces that chart:
int series = 3;
chart1.OpenData(COD.Values, series, (int)COD.Unknown);
chart1.OpenData(COD.XValues, series, (int)COD.Unknown);
chart1.AxisY.DataFormat.Decimals = 2;
chart1.AxisY.LabelsFormat.Decimals = 2;
double avg = 9.61;
double stddev = 2.57;
chart1.AxisY.Min = -6.95;
chart1.AxisY.Max = 14.09;
chart1.AxisX.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
double[] steps = new double[4];
int n  = 0;
steps[n++] = avg - stddev - chart1.AxisY.Min;
steps[n++] = stddev;
steps[n++] = stddev;
steps[n++] = chart1.AxisY.Max - avg - stddev;
for (int i = 0; i < series; i++)
{
int count = 2;
double val;
if (i == 0)
val = avg - stddev;
else if (i == 1)
val = avg;
else
val = avg + stddev;
for (int k = 0; k < count; k += 1)
{
chart1.Value[i, k] = val;
chart1.XValue[i, k] = k;
}
}
chart1.AxisY.CustomSteps = steps;
chart1.CloseData(COD.XValues);
chart1.CloseData(COD.Values);
"Ming Goi" <mgoi@angoss.com> wrote in message
news:ikW1EurqFHA.1992@webserver3.softwarefx.com...
> I think, I found a way to do this.
> I use the CustemSteps property, the label shows exactly where i want it to
> be....
>
> "Holger Wilken" <holger.wilken@megatel.de> wrote in message
> news:wlxzWpkqFHA.1724@webserver3.softwarefx.com...
> > (this answer appeared in a different thread, but belongs here, I think):
> >
> > Ok. The problem is you are adding a String label with the line:
> >
> >
> > Nowhere you are specifying where this label should go.
> >
> > The way String labels work in a numeric axis is through the LabelValue
> > property, this property makes the equivalence between the index of the
> label
> > (0 in this case) and the logical value in the axis, these labels are
> evenly
> > spaced.
> >
> > If you want to label an arbitrary value, completely independent of
Min/Max
> > and other Axis labels, the best option for you is a Constant Line.
> >
> > The following code adds a constant line displaying a label for the value
> > 2.37:
> >
> > ConstantLine cl = new ConstantLine();
> >
> > cl.Value = val;
> >
> > cl.Text = val.ToString();
> >
> > cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
> >
> >
> > Use this code INSTEAD of the YLeg code. Note that there is  no guarantee
> > that this label won't overlap another axis labels. If this is the ONLY
> label
> > you want in your axis, you may hide the regular axis labels by doing:
> >
> > chart1.AxisY.Style |= AxisStyle.HideText;
> >
> > --
> > www.chartfx.com
> >
> >
> >
> >
>
>```
##### Share on other sites

```Ming,
Have you tried Sections?
mySectionCount++;
mySection = FormChart.AxisY.Sections[ mySectionCount ];
mySection.From = 2.37;
mySection.To   = 2.37;
mySection.Grid.Color = System.Drawing.Color.Black;
mySection.Gridlines  = true;
mySection.Grid.Width = 2;
- LNS
Ming Goi wrote:
> Hi again,
> I still have problem.
> The CustomSteps seems to work for positive (Min/Max) only.
> Please take a look at the attach image.
> The blue labels are the ones, I want.
> I marked RED X for the ones, I don't want.
> If you can give a sample code for this would be great.
> Thanks again.
>
> Here is the code that produces that chart:
>
>    int series = 3;
>    chart1.OpenData(COD.Values, series, (int)COD.Unknown);
>    chart1.OpenData(COD.XValues, series, (int)COD.Unknown);
>    chart1.AxisY.DataFormat.Decimals = 2;
>    chart1.AxisY.LabelsFormat.Decimals = 2;
>    double avg = 9.61;
>    double stddev = 2.57;
>
>    chart1.AxisY.Min = -6.95;
>    chart1.AxisY.Max = 14.09;
>
>    chart1.AxisX.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
>
>    double[] steps = new double[4];
>    int n  = 0;
>    steps[n++] = avg - stddev - chart1.AxisY.Min;
>    steps[n++] = stddev;
>    steps[n++] = stddev;
>    steps[n++] = chart1.AxisY.Max - avg - stddev;
>    for (int i = 0; i < series; i++)
>    {
>     int count = 2;
>     double val;
>     if (i == 0)
>      val = avg - stddev;
>     else if (i == 1)
>      val = avg;
>     else
>      val = avg + stddev;
>
>     for (int k = 0; k < count; k += 1)
>     {
>      chart1.Value[i, k] = val;
>      chart1.XValue[i, k] = k;
>     }
>    }
>
>    chart1.AxisY.CustomSteps = steps;
>    chart1.CloseData(COD.XValues);
>    chart1.CloseData(COD.Values);
> "Ming Goi" <mgoi@angoss.com> wrote in message
> news:ikW1EurqFHA.1992@webserver3.softwarefx.com...
>
>>I think, I found a way to do this.
>>I use the CustemSteps property, the label shows exactly where i want it to
>>be....
>>
>>"Holger Wilken" <holger.wilken@megatel.de> wrote in message
>>news:wlxzWpkqFHA.1724@webserver3.softwarefx.com...
>>
>>>(this answer appeared in a different thread, but belongs here, I think):
>>>
>>>Ok. The problem is you are adding a String label with the line:
>>>
>>>
>>>Nowhere you are specifying where this label should go.
>>>
>>>The way String labels work in a numeric axis is through the LabelValue
>>>property, this property makes the equivalence between the index of the
>>
>>label
>>
>>>(0 in this case) and the logical value in the axis, these labels are
>>
>>evenly
>>
>>>spaced.
>>>
>>>If you want to label an arbitrary value, completely independent of
>
> Min/Max
>
>>>and other Axis labels, the best option for you is a Constant Line.
>>>
>>>The following code adds a constant line displaying a label for the value
>>>2.37:
>>>
>>>ConstantLine cl = new ConstantLine();
>>>
>>>cl.Value = val;
>>>
>>>cl.Text = val.ToString();
>>>
>>>cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
>>>
>>>
>>>Use this code INSTEAD of the YLeg code. Note that there is  no guarantee
>>>that this label won't overlap another axis labels. If this is the ONLY
>>
>>label
>>
>>>you want in your axis, you may hide the regular axis labels by doing:
>>>
>>>chart1.AxisY.Style |= AxisStyle.HideText;
>>>
>>>--
>>>www.chartfx.com
>>>
>>>
>>>
>>>
>>
>>
>
>```
##### Share on other sites

```Thanks for the suggestion...but it doesn't  work.
"LNS" <ianj_lns@lns-systems.com> wrote in message
news:SQCN8W4rFHA.1724@webserver3.softwarefx.com...
> Ming,
>
> Have you tried Sections?
>
> mySectionCount++;
> mySection = FormChart.AxisY.Sections[ mySectionCount ];
> mySection.From = 2.37;
> mySection.To   = 2.37;
> mySection.Grid.Color = System.Drawing.Color.Black;
> mySection.Gridlines  = true;
> mySection.Grid.Width = 2;
>
>
> - LNS
>
>
>
> Ming Goi wrote:
> > Hi again,
> > I still have problem.
> > The CustomSteps seems to work for positive (Min/Max) only.
> > Please take a look at the attach image.
> > The blue labels are the ones, I want.
> > I marked RED X for the ones, I don't want.
> > If you can give a sample code for this would be great.
> > Thanks again.
> >
> > Here is the code that produces that chart:
> >
> >    int series = 3;
> >    chart1.OpenData(COD.Values, series, (int)COD.Unknown);
> >    chart1.OpenData(COD.XValues, series, (int)COD.Unknown);
> >    chart1.AxisY.DataFormat.Decimals = 2;
> >    chart1.AxisY.LabelsFormat.Decimals = 2;
> >    double avg = 9.61;
> >    double stddev = 2.57;
> >
> >    chart1.AxisY.Min = -6.95;
> >    chart1.AxisY.Max = 14.09;
> >
> >    chart1.AxisX.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
> >
> >    double[] steps = new double[4];
> >    int n  = 0;
> >    steps[n++] = avg - stddev - chart1.AxisY.Min;
> >    steps[n++] = stddev;
> >    steps[n++] = stddev;
> >    steps[n++] = chart1.AxisY.Max - avg - stddev;
> >    for (int i = 0; i < series; i++)
> >    {
> >     int count = 2;
> >     double val;
> >     if (i == 0)
> >      val = avg - stddev;
> >     else if (i == 1)
> >      val = avg;
> >     else
> >      val = avg + stddev;
> >
> >     for (int k = 0; k < count; k += 1)
> >     {
> >      chart1.Value[i, k] = val;
> >      chart1.XValue[i, k] = k;
> >     }
> >    }
> >
> >    chart1.AxisY.CustomSteps = steps;
> >    chart1.CloseData(COD.XValues);
> >    chart1.CloseData(COD.Values);
> > "Ming Goi" <mgoi@angoss.com> wrote in message
> > news:ikW1EurqFHA.1992@webserver3.softwarefx.com...
> >
> >>I think, I found a way to do this.
> >>I use the CustemSteps property, the label shows exactly where i want it
to
> >>be....
> >>
> >>"Holger Wilken" <holger.wilken@megatel.de> wrote in message
> >>news:wlxzWpkqFHA.1724@webserver3.softwarefx.com...
> >>
> >>>(this answer appeared in a different thread, but belongs here, I
think):
> >>>
> >>>Ok. The problem is you are adding a String label with the line:
> >>>
> >>>
> >>>Nowhere you are specifying where this label should go.
> >>>
> >>>The way String labels work in a numeric axis is through the LabelValue
> >>>property, this property makes the equivalence between the index of the
> >>
> >>label
> >>
> >>>(0 in this case) and the logical value in the axis, these labels are
> >>
> >>evenly
> >>
> >>>spaced.
> >>>
> >>>If you want to label an arbitrary value, completely independent of
> >
> > Min/Max
> >
> >>>and other Axis labels, the best option for you is a Constant Line.
> >>>
> >>>The following code adds a constant line displaying a label for the
value
> >>>2.37:
> >>>
> >>>ConstantLine cl = new ConstantLine();
> >>>
> >>>cl.Value = val;
> >>>
> >>>cl.Text = val.ToString();
> >>>
> >>>cl.Flags |= ConstantFlag.HideLine | ConstantFlag.OutsideText;
> >>>
> >>>
> >>>Use this code INSTEAD of the YLeg code. Note that there is  no
guarantee
> >>>that this label won't overlap another axis labels. If this is the ONLY
> >>
> >>label
> >>
> >>>you want in your axis, you may hide the regular axis labels by doing:
> >>>
> >>>chart1.AxisY.Style |= AxisStyle.HideText;
> >>>
> >>>--
> >>>www.chartfx.com
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >```
##### Share on other sites

```When negative and positive numbers are involved CustomSteps works this way:
Use Step array going up (from 0 to Max) until Max is reached, then continue
using the array going down (from 0 to Min).
In your case, the first step is 13.99 used to go from 0 to 13.99, then it
uses 2.57 but the Max is exceeded, so it goes to zero and uses 2.57 (2nd in
the array) then 2.57 (3rd in the array) and then 1.91 (4th in the array).
If you want to go straight from Min to Max without breaking at zero do:
chart1.AxisY.Style &= ~AxisStyle.BreakZero;
Whit this, you will get the following labels:
6.95, 7.04, 9.61, 12.18, 14.09
--
www.chartfx.com```
##### Share on other sites

```Thanks for your reply.
As it turned out, all I need is
> chart1.AxisY.Style &= ~AxisStyle.BreakZero;
then everything works as expected.
Thanks again.
"SoftwareFX Support" <noreply@softwarefx.com> wrote in message
news:1F8%23%23L9rFHA.1720@webserver3.softwarefx.com...
> When negative and positive numbers are involved CustomSteps works this
way:
>
> Use Step array going up (from 0 to Max) until Max is reached, then
continue
> using the array going down (from 0 to Min).
>
> In your case, the first step is 13.99 used to go from 0 to 13.99, then it
> uses 2.57 but the Max is exceeded, so it goes to zero and uses 2.57 (2nd
in
> the array) then 2.57 (3rd in the array) and then 1.91 (4th in the array).
>
> If you want to go straight from Min to Max without breaking at zero do:
>
> chart1.AxisY.Style &= ~AxisStyle.BreakZero;
>
> Whit this, you will get the following labels:
>
> 6.95, 7.04, 9.61, 12.18, 14.09
>
> --
> www.chartfx.com
>
>```

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×