|
Full X-axis labels |
Posted by Eferov Ivan on Nov-17-2016 05:30 |
|
Hi
I draw graphs and on x-axis is not the last value. X-axis it is ordinal axis (0, 1, 2, 3, ...) and put my labels, but after draw last label not displayed. Why it happens?
My code:
public static List<double>[] yAsixDate = new List<double>[12];// Y coordinates
public static List<double>[] ordinalList = new List<double>[12];// X coordinates (1, 2, 3, ..., n, n+1)
public static List<double>[] xVisibleRange = new List<double>[12];// visible range X-axis
public static List<double>[] yVisibleRange = new List<double>[12];// visible range Y-axis
public static int startIndex, endIndex, noOfPoints;
private void LoadData()
{
........;
}
private void VisibleRange() //calculate visible range for all lines
{
double startX = viewer.getValueAtViewPort("x", viewer.ViewPortLeft);
double endX = viewer.getValueAtViewPort("x", viewer.ViewPortLeft + viewer.ViewPortWidth);
for (int i = 0; i != 12; i++)
{
startIndex = (int)Math.Floor(Chart.bSearch(ordinalList[i].ToArray(), startX));
endIndex = (int)Math.Ceiling(Chart.bSearch(ordinalList[i].ToArray(), endX));
noOfPoints = endIndex - startIndex + 1;
yVisibleRange[i].Clear();
xVisibleRange[i].Clear();
yVisibleRange[i].AddRange((double[])Chart.arraySlice(yAsixDate[i].ToArray(), startIndex, noOfPoints));
xVisibleRange[i].AddRange((double[])Chart.arraySlice(ordinalList[i].ToArray(), startIndex, noOfPoints));
}
}
private void refreshGraph()
{
VisibleRange();//calculate visible range for all lines
chartArea = new XYChart(Width - 16, Height - 142);
chartArea.setPlotArea(50, 5, Width - 16 - 100, Height - 142 - 57, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
chartArea.xAxis().setTickDensity(Width - 16 - 100);
chartArea.setClipping();
chartArea.yAxis2().syncAxis(chartArea.yAxis());
chartArea.yAxis().setAutoScale(0.01, 0.01, 0.01);
chartArea.xAxis().setLabelFormat("");
chartArea.xAxis().setLabelStyle("Arial", 6);
viewer.ZoomInWidthLimit = 25.0 / ordinalList[0].Count;
viewer.ZoomOutWidthLimit = 2115.0 / ordinalList[0].Count;
chartArea.xAxis().setLabels(xAsixDate[0].ToArray()); //add lables
viewer.setFullRange("x", ordinalList[0][0], ordinalList[0][ordinalList[0].Count - 1]);
viewer.syncLinearAxisWithViewPort("x", chartArea.xAxis());
for (int i = 0; i != 12; i++)
{
layer[i] = chartArea.addLineLayer(yVisibleRange[i].ToArray(), colorInteget[i]);
layer[i].setXData(xVisibleRange[i].ToArray());
layer[i].setLineWidth(wLines[i]);
}
viewer.Chart = chartArea;
}
The image can be seen that the axis is not the last label
|
Re: Full X-axis labels |
Posted by Eferov Ivan on Nov-17-2016 05:32 |
|
And whether you can do that after the schedule was free empty space? |
Re: Full X-axis labels |
Posted by Peter Kwan on Nov-18-2016 03:20 |
|
Hi Eferov,
As you are using ordinal values as the x-coordinates, but the x-axis is scrolled as a continuous variable, so it is possible the right side of the x-axis is not an integer. For example, if the chart is zoomed in so that the x-coordinates are from 4.00001 to 15.99999, then the label at x=16 will not appear, as it is outside of the x-axis range.
If you want the x-axis to always start and end at a label position, instead of using:
viewer.syncLinearAxisWithViewPort("x", chartArea.xAxis());
you can use:
double startX = Math.Floor(viewer.getValueAtViewPort("x", viewer.ViewPortLeft));
double endX = Math.Ceiling(viewer.getValueAtViewPort("x", viewer.ViewPortLeft + viewer.ViewPortWidth));
chartArea.xAxis().setLinearScale(startX, endX);
chartArea.xAxis().setRounding(false, false);
Hope this can help.
Regards
Peter Kwan |
Re: Full X-axis labels |
Posted by Eferov Ivan on Nov-20-2016 01:40 |
|
thank you very much, works!!
I do not want to create another topic, so I will ask here.
at a high magnification, I click on the arrow to scroll to the left and see that skipped big piece of chart. how to fix it?
pic1 - before scrolling
pic2 - after scrolling
look at the X-axis, I did only one click on the arrow of the scroll bar
|
Re: Full X-axis labels |
Posted by Peter Kwan on Nov-21-2016 22:54 |
|
Hi Eferov,
By "arrow to scroll to the left", are you referring to the arrow on the horizontal scrollbar?
The amount of scrolling is controlled by the scrollbar. You can configure the scrollbar to scroll by the amount you want. In some of our sample code, we configured it like the followings:
hScrollBar1.LargeChange = (int)Math.Ceiling(winChartViewer1.ViewPortWidth *
(hScrollBar1.Maximum - hScrollBar1.Minimum));
hScrollBar1.SmallChange = (int)Math.Ceiling(hScrollBar1.LargeChange * 0.1);
According to the above code, the "large change" will be the view of the viewport, while the
"small change" is 10% of the large change. You can modify the "small change" to fit your needs. See:
https://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbar.smallchange(v=vs.110).aspx
Hope this can help.
Regards
Peter Kwan |
|