SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please note, for the month of May we are trialling a switch to Stackoverflow.com for ad-hoc support of our chart controls. Please create an account and ask questions with the Tag=SciChart on Stackoverflow.

We welcome your feedback on this move as well, contact us to voice your opinion!

0
0

Can you help me please!
I was searching forum and see all different questions with dfferent ansvers but no one help for me.

I’m using CategoryDateAxis and whant to show to users vertical lines between days, weeks or month
Its depends from timestamp and visible period.
I need to opportunity to provide themself when to display vertical line.

In chart I display CandlestickSeries from stosk market and users whant to know when one day is ended and new day is begin.

How can I do that?

Version
2.1.0.2210
  • You must to post comments
0
0

Hi Evgeny,

Thanks for your inquiry.

To be honest with you, I’m not sure that I understand what the problem is. Did you have a chance to take a look on our annotation tutorial? It shows an example how to add periodical annotation in realtime chart. You can even go further and recycle annotations instead of recreating them ( e.g. when annotation goes outside viewport instead of removing it you can update its position ).

The only thing which you need to consider that in case of using CategoryDateAxis you’ll need to assign index of Date in data series instead of Date itself. So when you’ll need to write a code which takes VisibleRange of xAxis, then gets it’s min/max values to get index range in viewport. Then you’ll need to iterate through your xValues within that range ( from min to max ) and insert annotations at required points.

Hope this will help you!

Best regards,
Yura

  • Evgeny Khramov
    Can you help me? Which one is better for me? major/minor grid lines fits for me? I see some examples and try by myself but major/minor grid lines do not works foe me. How can I do that with major/minor grid lines?
  • Yura Khariton
    Well it depends on your needs. It’s still unclear for me how chart should look like with these vertical lines. Do you need to display axis tick labels only for these vertical lines and how chart should work when you zoom it? I’m asking because if you override grid lines drawing to draw them only at the end of day/month then when you zoom chart to display for example 1 hour then there will be no grid lines (major and minor ) and no axis tick labels(major). If this is not a problem for you then you can override grid lines drawing but because you’re using category axis I need to know about content of your data series. In case if first point in xValues contains beginning of day (e.g. if you pull and append data for entire day only ) and you know how many points are in one day then you can just set Major/MinorDelta to amount of points per day and major/minor grid lines will be drawn only at the beginning of each day ( gridlines for 0 points, then for 0 + MajorDelta point, then for 0 + 2MajorDelta and so on ). If your data series can start at any point of day then you’ll need to create custom TickProvider which will search the ends of the day/month within VisibleRange and will add them as major/minor ticks.
  • Evgeny Khramov
    In my case when I zoom chart I need labels for x axies Now I`m trying to display annotation and no luck Even if I try add “Watermark” annotation from AnnotationsAreEasyFragment example In my case I see no text If I add VerticalLineAnnotation I see no lines ( And thank you for advice about “in case of using CategoryDateAxis you’ll need to assign index of Date in data series instead of Date itself”Where can add annotations? Can I add them in onVisibleRangeChanged() method?
  • Yura Khariton
    Can you post your code here? Do you see any exceptions in logcat? And yes, you can add annotations in onVisibleRangeChanged() but because annotation is Android View you need to create and assign its properties on UI thread. You can use SciChart’s built-in helper class and call its Dispatcher.runOnUiThread() method or use built-in functionality provided by Android (e.g. Activity.runOnUiThread() method and other similar alternatives )
  • Evgeny Khramov
    I posted code below
0
0
This is my code

@Override
public void onVisibleRangeChanged(IAxisCore iAxisCore, IRange iRange, IRange iRange1, boolean b) {

    // 184.0 in my case
Double min = (Double) iAxisCore.getVisibleRange().getMin();
// 210.0 in my case
Double max = (Double) iAxisCore.getVisibleRange().getMax();

UpdateSuspender.using(mChart, new Runnable() {
    @Override
    public void run() {
        final SciChartBuilder sciChartBuilder = SciChartBuilder.instance();
        DateTime prevDate = null; // previous date for checking if new day
        mChart.getAnnotations().clear();
        for (Double i = min; i <= max; i++) { from 184.0 to 210.0 
            Date date = mOhlcDataSeries.getXValues().get(i.intValue()); // get first visible date
            if (prevDate == null) { // save previous date and continue
                prevDate = new DateTime(date.getTime()); // org.joda.time.DateTime
                continue;
            }

            final DateTime dateTime = new DateTime(date.getTime());

            // check if new day
            if (!dateTime.withTimeAtStartOfDay().isEqual(prevDate.withTimeAtStartOfDay())) {

                final VerticalLineAnnotation annotation = sciChartBuilder.newVerticalLineAnnotation()
                                .withXValue(i) // this not work
                                                    //.withX1(i)   // this not work
                        .withVerticalGravity(Gravity.FILL_VERTICAL)
                        .withStroke(2, ColorUtil.Brown)
                        .withAnnotationLabel()
                        .withAnnotationLabel(LabelPlacement.TopRight, "Bottom-aligned", 90)
                        .build();

                mChart.getAnnotations().add(annotation);
            }

            prevDate = dateTime;
        }
    }
});

dispatchVisibleRangeChanged();

}

  • You must to post comments
0
0

I ckeck this code in CandlestickChartFragment from examples
I don’t know why but vertical lines desplayed
If I scroll chart then candles scrols BUT vertical lines stays in the same position
Labels in lines changes but positions not match candle positions

  • You must to post comments
0
0

Hi Evgeny,

The line stays on same position because you’re using ‘i’ value as xValue for annotation and it’s calculated by incrementing min value of visible range in for loop. This means that if min = 0.5 then i values will be [0.5, 1.5, 2.5, …], if min = 0.7 then i will have [0.7, 1.7, 2.7, …] values an so on but the problem is that all these values will be translated to the same coordinates on screen ( min will be always transformed to 0 pixel on screen because it’s edge of the viewport and because other points are calculated by incrementing min value they will be transformed to same coordinates when you pan chart ).

Please try next code:

 final VerticalLineAnnotation annotation = sciChartBuilder.newVerticalLineAnnotation()
          .withXValue(i.intValue() - 0.5)
          .build();

We need to substract 0.5 to shift annotation to the left with offset which equal to half of data point ( in category axis distance between two points is constant and equal to 1 because it works with indices ). This is required to prevent drawing of vertical line at the center of candle

Hope this will help you!

Best regards,
Yura

  • Evgeny Khramov
    Thank you Today I have no time to check Will raplay you ASAP
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.