0

我有一些从 excel 导入到 Nebula 模型的股票数据。我有图表工作的可视化,但我无法正确格式化沿 x 轴的时间。我尝试为每个坐标值创建一个带有 1 个数据点的 temp x 数组,并且我已经成功创建了一个相同长度的日期数组。在我看来,我应该能够告诉 Nebula 使用我的日期数组作为 x 轴上的标签,但我不知道要修改 x 轴的哪个参数。现在,启用日期格式后,它从 1969 年 10 月 1 日开始,然后有未标记的刻度线,直到最后一个也显示 1969 年 10 月 1 日(默认值?)这是我的一些代码:

    //Data source
    List<Book> stocks = readBooksFromCSV("COVID_DJI.csv");
    for (Book b : stocks) {
        System.out.println(b);
    }

            //Create arrays that can hold output
            double[] opening;
            double[] closing;
            String[] time;
            int len = stocks.size();
            opening = new double[len];
            closing = new double[len];
            time = new String[len];
            int j = 0;
            for (Book x : stocks) {
                double o_value = x.getOpen();
                double c_value = x.getClose();
                String d_value = x.getDate();
                opening[j] = o_value;
                closing[j] = c_value;
                time[j] = d_value;
                j++;
            }

            Date[] dates = new Date[len];
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            for(int i = 0; i < len; i++) {
                try {
                    dates[i] = df.parse(time[i]);
                }
                catch(ParseException e) {
                    System.out.println("Ooof...");
                }
            }

            //Create temp x array
            double[] temp;
            temp = new double[len];
            for (int i = 0; i < len; i++) {
                temp[i] = i;
            }

            //Shell window generation and lightweight system- omitted

    XYGraph xyGraph = new XYGraph();
    xyGraph.setTitle("DJIA PPS During COVID-19 Outbreak");

    //Set Axis Bounds
    double min = opening[0];
    for(int i = 0; i < len; i++) {
        if(opening[i] < min) {
            min = opening[i];
        }
    }
    double max = opening[0];
    for(int i = 0; i < len; i++) {
        if(opening[i] > max) {
            max = opening[i];
        }
    }
    double drop = ((max - min)/max) * 100;
    System.out.println("Peak to trough drop: " + drop + "%");

    //Set axis parameters **I think this is where I need to change a parameter
    xyGraph.getPrimaryXAxis().setRange(0, len);
    xyGraph.getPrimaryXAxis().setDateEnabled(true);
    xyGraph.getPrimaryXAxis().setTimeUnit(Calendar.DATE);
    xyGraph.getPrimaryXAxis().setFormatPattern("yyyy-MM-dd");
    xyGraph.getPrimaryXAxis().setMajorGridStep(7);
    xyGraph.getPrimaryYAxis().setRange(min-100,max+100);
    xyGraph.getPrimaryYAxis().setFormatPattern("$00000.00");
    xyGraph.getPrimaryXAxis().setTitle("Day");
    xyGraph.getPrimaryYAxis().setTitle("Price Per Share");

    //Plot graph
    lws.setContents(xyGraph);

    //Trace implementation- omitted
4

0 回答 0