如何在swift 3中绘制LineChartData?

时间:2016-09-16 12:47:18

标签: ios swift3 ios-charts

我切换到swift 3,现在我正在努力让我的图表数据再次显示出来。当我像这样使用它时,我只看到一个空图表。 我认为一些初始化程序发生了变化?

我正在使用Swift-3.0分支。

private void init(final Context context, AttributeSet attrs) {

    if (attrs != null) {
        TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CountWidget, 0, 0);
        max = attributes.getInt(R.styleable.CountWidget_max, Integer.MAX_VALUE);
        min = attributes.getInt(R.styleable.CountWidget_min, 0);
    }

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.count_widget, this, true);

    final LinearLayout container = (LinearLayout) getChildAt(0);

    minusButton = (ImageView) container.getChildAt(0);
    countView = (EditText) container.getChildAt(1);
    plusButton = (ImageView) container.getChildAt(2);

    countView.setText(Integer.toString(min));
    countView.setCursorVisible(true);

    minusButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            hideKeypad(context);
            String countText = countView.getText().toString();
            int count = min;
            if (!countText.isEmpty()) {
                try {
                    count = Integer.parseInt(countText);
                } catch (NumberFormatException e) {
                    count = min;
                }
            }
            if (count > min) count--;
            countView.setText(Integer.toString(count));

            if (onButtonClickListener != null) {
                onButtonClickListener.OnMinusButtonClick(count);
            }
        }
    });

    plusButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            hideKeypad(context);
            String countText = countView.getText().toString();
            int count = max;
            if (!countText.isEmpty()) {
                try {
                    count = Integer.parseInt(countText);
                } catch (NumberFormatException e) {
                    count = min;
                }
            }
            if (count < max) count++;
            countView.setText(Integer.toString(count));

            if (onButtonClickListener != null) {
                onButtonClickListener.OnPlusButtonClick(count);
            }
        }
    });

    countView.addTextChangedListener(new TextWatcher() {

        private int previousCount;
        private int currentCount;

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.length() == 0 || !isNumber(String.valueOf(charSequence))) {
                previousCount = 0;
            } else {
                previousCount = Integer.valueOf(String.valueOf(charSequence));
            }
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.length() == 0 || !isNumber(String.valueOf(charSequence))) {
                currentCount = 0;
            } else {
                currentCount = Integer.valueOf(String.valueOf(charSequence));
            }
            if (currentCount == previousCount) return;
            if (onCountChangeListener != null) {
                // value is updated into basket
                onCountChangeListener.onCountChange(currentCount);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });
}

1 个答案:

答案 0 :(得分:11)

他们改变了方式,如何构建数据。随函附上以下样本:

a = np.array([
   [0, 0],
   [1, 1],
   [1, 9]
])