点击角度为2的条形高图表上的事件

时间:2018-04-25 13:18:00

标签: angular highcharts

如何将图表类型为bar的高角度图表添加角度2点击事件? 我正在尝试使用以下代码:

let chart = new highCharts.Chart('container', Class1.createBarChart());
chart.series.click = this.clickBars();

clickBars() {
  console.log('bar clicked');
}

由于技术限制,我不想使用<chart>指令。 另外,我不想在高图表配置对象中调用click事件。 请让我知道适当的解决方案。

编辑:

我根据建议尝试了下面的代码:

 chart.options.plotOptions.series.point.events.click = (function(event) { this.clickBars(event) }).bind(this);

但是这里this.clickBars未定义。虽然我已经在班上创建了一个函数。

如果我使用的代码如下:

chart.options.plotOptions.series.point.events.click = (event) => this.clickBars(event);

然后它返回非法的回复陈述&#39;。

2 个答案:

答案 0 :(得分:3)

我在添加系列时这样做:

chart.addSeries({
  ...
  events: {
    click: (event: AreaClickEvent) => this.clickBars(event),
  },
});

您还可以在plotOptions中注册一次点击处理程序。类似的东西:

chart.options.plotOptions.series.events.click = (event) => this.clickBars(event);

<强>更新

看来你还需要调用更新。这是一个有效的jsfiddle: http://jsfiddle.net/80k0ojyh/

答案 1 :(得分:0)

我希望这会有所帮助。在调用highcharts-chart的模板中,为所有DOM元素添加单击输出装饰器。万一得到,将会有点信息。 刚才在您的组件(ts文件)中声明了功能 onPointSelect

模板

public class UploadSheetToServerService extends Service {
    public static final int USERVICE_ID = 12;
    public static final String KEY_MOBILE_LIST = "KEY_MOBILE_LIST";
    public static final int CONTACTS_INTERVAL = 500;
    private List<SheetToServerModel> mMobileList;
    private FirebaseFirestore mFB;
    private int totalRemainedCount;
    private int startingInterval;
    private int endingInterval;
    private WriteBatch batch;
    private int checkDocumentAPIHitsCount;
    private int totalOnGoingDocsCount ;


    public UploadSheetToServerService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        mFB = FirebaseFirestore.getInstance();
        startForeground(USERVICE_ID, buildForegroundNotification("Uploading sheet contacts"));
        mMobileList = NgSingleton.getInstance().getSheetToServerModelList();
        removeNullNumbers(mMobileList);
        /*mMobileList = createDummyList();*/
        if (!ListUtilities.isNull(mMobileList) && mMobileList.size() > 0) {
            totalRemainedCount = mMobileList.size();
            startingInterval = 0;
            endingInterval = 0;
            do {
                List<SheetToServerModel> partList = new ArrayList<>();
                if (totalRemainedCount > CONTACTS_INTERVAL) {
                    partList.clear();
                    endingInterval = startingInterval + CONTACTS_INTERVAL;
                    for (int i = startingInterval; i < endingInterval; i++) {
                        partList.add(mMobileList.get(i));
                    }
                    startingInterval = endingInterval;
                    totalRemainedCount -= CONTACTS_INTERVAL;
                    prepareAndSendContactsByParts(partList);
                } else {
                    if (totalRemainedCount == mMobileList.size()) {    //Actual list is < 500.
                        partList.clear();
                        endingInterval = totalRemainedCount;
                        for (int i = startingInterval; i < endingInterval; i++) {
                            partList.add(mMobileList.get(i));
                        }
                        totalRemainedCount = 0;                                         //last list
                        prepareAndSendContactsByParts(partList);
                    } else {                //above if block executed   //Actual list is > 500. After chucked it came to here
                        partList.clear();
                        for (int i = startingInterval; i < mMobileList.size(); i++) {
                            partList.add(mMobileList.get(i));
                        }
                        totalRemainedCount = 0;                                            //last list
                        prepareAndSendContactsByParts(partList);
                    }
                }
            } while (totalRemainedCount > 0);

            stopSelf();
        }


        return START_STICKY;
    }




    private void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }


    private Notification buildForegroundNotification(String filename) {
        NotificationCompat.Builder b = new NotificationCompat.Builder(this, "1");
        b.setOngoing(true)
                .setContentTitle(getString(R.string.uploading))
                .setContentText(filename)
                .setSmallIcon(android.R.drawable.stat_sys_upload)
                .setTicker(getString(R.string.uploading));

        return (b.build());
    }

    public void prepareAndSendContactsByParts(List<SheetToServerModel> list) {
        UploadTask uploadTask = new UploadTask(list);
        try {
            uploadTask.execute().get();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (!ListUtilities.isNull(list))
            Log.d("UploadSheetToServer", "prepareAndSendContactsByParts: " + list.size());
    }

    private void uploadBulkContacts(List<SheetToServerModel> list) {
        uploadContactToFS(mFB, list);

    }

    public void uploadContactToFS(FirebaseFirestore fb, List<SheetToServerModel> contactModels) {
        // Get a new write batch
        batch = fb.batch();
        totalOnGoingDocsCount += contactModels.size();
        for (int i = 0; i < contactModels.size(); i++) {

            if (!StringUtilities.isNull(contactModels.get(i).getPhoneNumber())) {
                // Set the value of 'NYC'
                DocumentReference nycRef = fb.collection("users1").document(contactModels.get(i).getPhoneNumber());
                Map<String, Object> updateOrAddFields = new HashMap<>();
                /* bookNo, receiptNo, name, phoneNumber, email, devoteeName, houseOrPlotNo, flatNo, roadNo, nameOfApartment, colony, area, landmark, comment, donation, modeOfPaymentDetails, receivedDate*/
                updateOrAddFields.put("bookNo", contactModels.get(i).getBookNo());
                updateOrAddFields.put("receiptNo", contactModels.get(i).getReceiptNo());
                updateOrAddFields.put("name", contactModels.get(i).getNamePartsList());
                updateOrAddFields.put("phoneNumber", contactModels.get(i).getPhoneNumber());
                updateOrAddFields.put("email", contactModels.get(i).getEmail());
                updateOrAddFields.put("devoteeName", contactModels.get(i).getDevoteeName());

                /* tiHouseNoPlotNo2 tiFlatNo2 tiBlockNo2 tiApartment2 roadNo2, tiColony2 tiArea2 tiLandmark2 tiCity2 tiState2 tiPincode2*/
                updateOrAddFields.put("cAddressModel", Arrays.asList(
                        contactModels.get(i).getHouseNo(),
                        contactModels.get(i).getFlatNo(),
                        ""/* Empty For block no*/,
                        contactModels.get(i).getNameOfApartment(),
                        contactModels.get(i).getRoadNo(),
                        contactModels.get(i).getColony(),
                        contactModels.get(i).getArea(),
                        contactModels.get(i).getLandmark(),
                        "", "", ""));

                updateOrAddFields.put("comment", contactModels.get(i).getComment());
                //updateOrAddFields.put("donation", contactModels.get(i).getDonation());
                updateOrAddFields.put("modeOfPaymentDetails", contactModels.get(i).getModeOfPaymentDetails());
                //updateOrAddFields.put("receivedDate", contactModels.get(i).getReceivedDate());
                updateOrAddFields.put("howWeCameToKnow", contactModels.get(i).getCategory());



                checkDocumentExists(fb, i,  nycRef, updateOrAddFields, contactModels);
                Log.d("USTSS", "uploadContactToFS: ");



            }
            Log.d("USTS", "time start: "+ System.currentTimeMillis());
        }







    }
    public void checkDocumentExists(FirebaseFirestore fb, int position,  DocumentReference nycRef, Map<String, Object> updateOrAddFields, List<SheetToServerModel> contactModels ){
        DocumentReference docRef = fb.collection("users1").document(contactModels.get(position).getPhoneNumber());
        docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                    checkDocumentAPIHitsCount++;
                    DocumentSnapshot document = task.getResult();
                    if (document.exists()) {
                        batch.update(nycRef, updateOrAddFields);
                    } else {
                        batch.set(nycRef, updateOrAddFields);
                    }
                    batch.update(nycRef, "donationList", FieldValue.arrayUnion(contactModels.get(position).getDonation()));
                    //nycRef.update("donationList", FieldValue.arrayUnion(contactModels.get(i).getDonation()));
                    String donationDetails = String.valueOf(contactModels.get(position).getDonation());
                    donationDetails += ":: ::" + contactModels.get(position).getReceivedDate() + "::" + contactModels.get(position).getModeOfPaymentDetails();
                    //nycRef.update("donationDetailsList", FieldValue.arrayUnion(donationDetails));
                    batch.update(nycRef, "donationDetailsList", FieldValue.arrayUnion(donationDetails));
                    if(checkDocumentAPIHitsCount == totalOnGoingDocsCount)
                    h.sendEmptyMessage(-1);
                    Log.d("USTSStime", "hits: "+ checkDocumentAPIHitsCount +" "+totalOnGoingDocsCount);
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
            }
        });
    }

    Handler h = new Handler(){
        @Override
        public void handleMessage(Message msg){
            Log.d("USTSS", "handleMessage: ");
            // Commit the batch         //todo below }
            batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    showToast("All contacts added successfully");
                }
            });
        }
    };



    private class UploadTask extends AsyncTask<Void, Void, Void> {
        private List<SheetToServerModel> modelList;

        public UploadTask(List<SheetToServerModel> modelList) {
            this.modelList = modelList;
        }

        @Override
        protected Void doInBackground(Void... voids) {
            uploadBulkContacts(modelList);
            return null;
        }
    }

}