|
Trendlayer |
Posted by Bill on Jul-13-2020 13:43 |
|
How do I remove the excessed trendlayer line from my graph. I want only up to the middle of my graph.
This is my code:
Eventhough my data array is up to the middle only.
TrendLayer trendLayer = c.addTrendLayer(TREND, c.dashLineColor(0x808080, Chart.DashLine), "REGRESSION LINE");
trendLayer.setLineWidth(2);
trendLayer.moveFront();
|
Re: Trendlayer |
Posted by Peter Kwan on Jul-14-2020 01:52 |
|
Hi Bill,
You can use an x-zone color for the trend line. For example:
// Dash line color if x is smaller than xLimit, and transparent if x is larger than xLimit.
int trendLineColor = c.xZoneColor(xLimit, c.dashLineColor(0x808080, Chart.DashLine), Chart.Transparent);
TrendLayer trendLayer = c.addTrendLayer(TREND, trendLineColor, "REGRESSION LINE");
Regards
Peter Kwan |
Re: Trendlayer |
Posted by Bill on Jul-14-2020 06:27 |
|
Still not working. Not sure if there is a relationship in my x axis label value, as shown in the graph below?
|
Re: Trendlayer |
Posted by Peter Kwan on Jul-14-2020 12:10 |
|
Hi Bill,
Just from the graph, it is not certain the type of coordinates you are using on the x-axis. It can be a numeric x-axis, or it can be a label based x-axis.
If the x-axis is configured using Axis.setLabels, it is a label based x-axis. The labels on the x-axis are just names for human reading, and have no meaning to the code. In this case, the line usually has no x-coordinates (no Layer.setXData). The x-coordinates are assumed to be the array index, so each point in the line with match the corresponding label on the x-axis. In this case, the x-coordinate for the x-zone color should be 13, as it is the 14th label on the x-axis.
If your code uses Layer.setXData to provide numeric coordinates to the line, and/or using Axis.setLinearScale to configure the x-axis (if it is not used, the x-axis will be auto-scaled like the y-axis). In this case, the x-axis is numeric, and you should use the same coordinate in the Layer.setXData array for the x-zone color.
Hope this can help.
Regards
Peter Kwan |
Re: Trendlayer |
Posted by Bill on Jul-14-2020 12:56 |
|
I got it. I just follow what you've said. I put it in this way. and it worked!. Thanks a lot.
int trendLineColor = c.xZoneColor(13, c.dashLineColor(0x808080, Chart.DashLine), Chart.Transparent);
TrendLayer trendLayer = c.addTrendLayer(TREND, trendLineColor, "REGRESSION LINE"); |
|