チャート:編集可能な注釈

このページでは、FlexChartに注釈を表示および編集する方法を示します。

このサンプルでは、次の注釈編集操作がサポートされます。

  • チャート左上の注釈ボタンをクリックして、チャートのプロット領域をクリックまたはドラッグして、注釈を追加できます。
  • 左端の[データ座標]ボタンをクリックして、追加する注釈の座標を絶対座標とデータ座標から選択できます。絶対座標ではスクロールしても表示位置が変わりません。
  • 新しいボタンを追加してカスタム注釈を作成できます。ここでは黄色の三角形ボタンを追加しています。
  • チャート上で注釈をドラッグできます。
  • 注釈をダブルクリックして、テキストを編集できます。
  • [X]ボタンを使用して注釈を削除できます。
import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as core from '@grapecity/wijmo'; import * as chart from '@grapecity/wijmo.chart'; import * as annotation from '@grapecity/wijmo.chart.annotation'; import { getData } from './data'; import { EditableAnnotationLayer, Button } from './EditableAnnotationLayer'; import { AxisScrollbar } from './AxisScrollbar'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the chart let al; let chkbox = document.querySelector('#checkboxIsEditable'); chkbox.addEventListener('change', () => { al.isEditable = chkbox.checked; }); let theChart = new chart.FlexChart('#theChart', { bindingX: 'x', chartType: 'Scatter', itemsSource: getData(), tooltip: { content: '' }, series: [ { name: 'データ', binding: 'y' } ], rendered: () => { if (!al) { al = new EditableAnnotationLayer(theChart); al.isEditable = chkbox.checked; //add customize button var triangle, triangleBtn = new Button(function (engine) { var triangleIcon = new annotation.Polygon({ tooltip: 'カスタム - 三角 </br>ドラッグして三角の注釈を追加します。', points: [{ x: 10, y: 5 }, { x: 5, y: 15 }, { x: 15, y: 15 }], style: { fill: 'yellow' } }); triangleIcon.render(engine); return triangleIcon._element; }, function (point, isDataCoordinate) { var x = isDataCoordinate ? point.dx : point.x, y = isDataCoordinate ? point.dy : point.y; triangle = new annotation.Polygon({ attachment: isDataCoordinate ? annotation.AnnotationAttachment.DataCoordinate : annotation.AnnotationAttachment.Absolute, tooltip: 'カスタム注釈 - 三角', points: [{ x: x, y: y }, { x: x, y: y }, { x: x, y: y }], style: { fill: 'yellow' } }); al.items.push(triangle); }, function (originPoint, currentPoint, isDataCoordinate) { var ox = isDataCoordinate ? originPoint.dx : originPoint.x, oy = isDataCoordinate ? originPoint.dy : originPoint.y, cx = isDataCoordinate ? currentPoint.dx : currentPoint.x, cy = isDataCoordinate ? currentPoint.dy : currentPoint.y, offsetX = Math.abs(cx - ox), offsetY = cy - oy, isXDate = core.isDate(ox), isYDate = core.isDate(oy), oaDate = chart.FlexChart._fromOADate; triangle.points.clear(); triangle.points.push({ x: ox, y: isYDate ? oaDate(oy - offsetY) : oy - offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - offsetX) : ox - offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - 0 + offsetX) : ox + offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); }); al.buttons.push(triangleBtn); //add pre-defined annotations. var watermarker = new annotation.Text({ position: annotation.AnnotationPosition.Left | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, text: 'watermarker', tooltip: 'テキストの透かし', point: { x: 1, y: 1 }, style: { 'fill': '#cccccc', 'font-size': '30px', opacity: 0.2 } }); al.items.push(watermarker); var imgmarker = new annotation.Image({ position: annotation.AnnotationPosition.Right | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, tooltip: '画像の透かし', point: { x: 0, y: 1 }, width: 128, height: 33, href: 'resources/wijmo-logo-text.png', style: { opacity: 0.2 } }); al.items.push(imgmarker); var centerHLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.DataCoordinate, position: annotation.AnnotationPosition.Center, content: '垂直線', start: { x: 50, y: 0 }, end: { x: 50, y: 1000 }, style: { 'stroke-width': '2px', stroke: 'green' } }); al.items.push(centerHLine); var centerVLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.Relative, position: annotation.AnnotationPosition.Center, content: '水平線', start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 }, style: { 'stroke-width': '2px', stroke: 'red' } }); al.items.push(centerVLine); var topRange = new annotation.Polygon({ attachment: annotation.AnnotationAttachment.Relative, points: [{ x: 0, y: 0 }, { x: 0, y: 0.2 }, { x: 1, y: 0.2 }, { x: 1, y: 0 }], content: '上端の範囲', style: { fill: '#FEF0DB', opacity: 0.5, stroke: '#FEF0DB' } }); al.items.push(topRange); //flag var pointIndex = 10; ['black', 'blue', 'green', 'red', 'yellow'].forEach(function (v) { var flagSrc = 'resources/flag-' + v + '-icon.png'; var flag = new annotation.Image({ attachment: annotation.AnnotationAttachment.DataIndex, seriesIndex: 0, pointIndex: pointIndex, width: 24, height: 24, href: flagSrc }); al.items.push(flag); pointIndex += 10; }); var rect = new annotation.Rectangle({ attachment: annotation.AnnotationAttachment.DataCoordinate, point: { x: 10, y: 650 }, width: 120, height: 150, style: { 'stroke-dasharray': '4 4', stroke: 'red' } }); al.items.push(rect); var circle = new annotation.Circle({ seriesIndex: 0, attachment: annotation.AnnotationAttachment.DataCoordinate, radius: 80, point: { x: 70, y: 350 }, style: { stroke: 'blue', fill: 'blue', opacity: 0.3 } }); al.items.push(circle); } } }); let axisScrollBar = new AxisScrollbar(theChart.axes[0]); window.setTimeout(function () { axisScrollBar.maxPos = 0.5; }, 20); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Editable Annotations</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <label id="labelIsEditable" for="checkboxIsEditable">編集可能:</label> <input type="checkbox" id="checkboxIsEditable" checked="checked" /></br> <div id="theChart"></div> </div> </body> </html> // generate some random data export function getData() { var data = [], numCount = 100; for (var i = 0; i < numCount; i++) { data.push({ x: getRandomValue(100), y: getRandomValue(1000) }); } return data; } // function getRandomValue(max) { return Math.round(Math.random() * max); } .wj-flexchart { margin: 10px 0; } body { margin-bottom: 24pt; } .wj-flexchart .wjanno-editable-layer .wjanno-container { fill: #eee; stroke: #666; stroke-width: 1; } .wj-flexchart .wjanno-editable-layer .wjanno-dc-icon .wjanno-container { fill: #eee; } .wj-flexchart .wjanno-editable-layer .wjanno-icon-selected .wjanno-container { fill: #89E; } .no-selection { user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; } .wj-flexchart { padding-bottom: 25px; } /**** Axis Scrollbar Css *****/ .wj-flexchart .wj-axis-scrollbar-container { position: relative; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-rangeslider { border: 1px solid #EAEAEA; background-color: #EAEAEA; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; border-top-left-radius: 6px; border-top-right-radius: 6px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-hrangeslider { height: 20px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-vrangeslider { width: 20px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, Inject, enableProdMode, ViewChild, NgModule, AfterViewInit } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { WjChartModule } from '@grapecity/wijmo.angular2.chart'; import { DataService } from './app.data'; import { EditableAnnotationLayer, Button } from './EditableAnnotationLayer'; import { AxisScrollbar } from './AxisScrollbar'; import * as core from '@grapecity/wijmo'; import * as wjChart from '@grapecity/wijmo.chart'; import * as annotation from '@grapecity/wijmo.chart.annotation'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent implements AfterViewInit { data: any[]; isEditable: boolean; al: EditableAnnotationLayer; @ViewChild('theChart') theChart: wjChart.FlexChart; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); this.isEditable = true; } // editableChange() { if(this.al) { this.al.isEditable = this.isEditable; } } // chartRendered() { let al = this.al; if (!al) { al = new EditableAnnotationLayer(this.theChart); this.al = al; al.isEditable = this.isEditable; //add customize button var triangle: any, triangleBtn = new Button(function (engine: wjChart.IRenderEngine) { var triangleIcon = new annotation.Polygon({ tooltip: 'カスタム - 三角 </br>ドラッグして三角の注釈を追加します。', points: [{ x: 10, y: 5 }, { x: 5, y: 15 }, { x: 15, y: 15 }], style: { fill: 'yellow' } }); triangleIcon.render(engine); return triangleIcon._element; }, function (point: any, isDataCoordinate: boolean) { var x = isDataCoordinate ? point.dx : point.x, y = isDataCoordinate ? point.dy : point.y; triangle = new annotation.Polygon({ attachment: isDataCoordinate ? annotation.AnnotationAttachment.DataCoordinate : annotation.AnnotationAttachment.Absolute, tooltip: 'カスタム注釈 - 三角', points: [{ x: x, y: y }, { x: x, y: y }, { x: x, y: y }], style: { fill: 'yellow' } }); al.items.push(triangle); }, function (originPoint: any, currentPoint: any, isDataCoordinate: boolean) { var ox = isDataCoordinate ? originPoint.dx : originPoint.x, oy = isDataCoordinate ? originPoint.dy : originPoint.y, cx = isDataCoordinate ? currentPoint.dx : currentPoint.x, cy = isDataCoordinate ? currentPoint.dy : currentPoint.y, offsetX = Math.abs(cx - ox), offsetY = cy - oy, isXDate = core.isDate(ox), isYDate = core.isDate(oy), oaDate = wjChart.FlexChart._fromOADate; triangle.points.clear(); triangle.points.push({ x: ox, y: isYDate ? oaDate(oy - offsetY) : oy - offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - offsetX) : ox - offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - 0 + offsetX) : ox + offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); }); al.buttons.push(triangleBtn); //add pre-defined annotations. var watermarker = new annotation.Text({ position: annotation.AnnotationPosition.Left | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, text: 'watermarker', tooltip: 'テキストの透かし', point: { x: 1, y: 1 }, style: { 'fill': '#cccccc', 'font-size': '30px', opacity: 0.2 } }); al.items.push(watermarker); var imgmarker = new annotation.Image({ position: annotation.AnnotationPosition.Right | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, tooltip: '画像の透かし', point: { x: 0, y: 1 }, width: 128, height: 33, href: 'resources/wijmo-logo-text.png', style: { opacity: 0.2 } }); al.items.push(imgmarker); var centerHLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.DataCoordinate, position: annotation.AnnotationPosition.Center, content: '垂直線', start: { x: 50, y: 0 }, end: { x: 50, y: 1000 }, style: { 'stroke-width': '2px', stroke: 'green' } }); al.items.push(centerHLine); var centerVLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.Relative, position: annotation.AnnotationPosition.Center, content: '水平線', start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 }, style: { 'stroke-width': '2px', stroke: 'red' } }); al.items.push(centerVLine); var topRange = new annotation.Polygon({ attachment: annotation.AnnotationAttachment.Relative, points: [{ x: 0, y: 0 }, { x: 0, y: 0.2 }, { x: 1, y: 0.2 }, { x: 1, y: 0 }], content: '上端の範囲', style: { fill: '#FEF0DB', opacity: 0.5, stroke: '#FEF0DB' } }); al.items.push(topRange); //flag var pointIndex = 10; ['black', 'blue', 'green', 'red', 'yellow'].forEach(function (v) { var flagSrc = 'resources/flag-' + v + '-icon.png'; var flag = new annotation.Image({ attachment: annotation.AnnotationAttachment.DataIndex, seriesIndex: 0, pointIndex: pointIndex, width: 24, height: 24, href: flagSrc }); al.items.push(flag); pointIndex += 10; }); var rect = new annotation.Rectangle({ attachment: annotation.AnnotationAttachment.DataCoordinate, point: { x: 10, y: 650 }, width: 120, height: 150, style: { 'stroke-dasharray': '4 4', stroke: 'red' } }); al.items.push(rect); var circle = new annotation.Circle({ seriesIndex: 0, attachment: annotation.AnnotationAttachment.DataCoordinate, radius: 80, point: { x: 70, y: 350 }, style: { stroke: 'blue', fill: 'blue', opacity: 0.3 } }); al.items.push(circle); } } // ngAfterViewInit() { let axisScrollBar = new AxisScrollbar(this.theChart.axes[0]); window.setTimeout(function () { axisScrollBar.maxPos = 0.5; }, 20); } } // @NgModule({ imports: [FormsModule, WjChartModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Editable Annotations</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="form-group"> </div> <div class="form-group"> <label id="labelIsEditable" for="checkboxIsEditable">編集可能:</label> <input type="checkbox" id="checkboxIsEditable" [(ngModel)]="isEditable" (change)="editableChange()" /> <wj-flex-chart #theChart bindingX="x" chartType="Scatter" [itemsSource]="data" tooltipContent="" (rendered)="chartRendered()"> <wj-flex-chart-series name="データ" binding="y"></wj-flex-chart-series> </wj-flex-chart> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { var data = [], numCount = 100; for (var i = 0; i < numCount; i++) { data.push({ x: this.getRandomValue(100), y: this.getRandomValue(1000) }); } return data; } // getRandomValue(max: number) { return Math.round(Math.random() * max); } } .wj-flexchart { margin: 10px 0; } body { margin-bottom: 24pt; } .wj-flexchart .wjanno-editable-layer .wjanno-container { fill: #eee; stroke: #666; stroke-width: 1; } .wj-flexchart .wjanno-editable-layer .wjanno-dc-icon .wjanno-container { fill: #eee; } .wj-flexchart .wjanno-editable-layer .wjanno-icon-selected .wjanno-container { fill: #89E; } .no-selection { user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; } .wj-flexchart { padding-bottom: 25px; } /**** Axis Scrollbar Css *****/ .wj-flexchart .wj-axis-scrollbar-container { position: relative; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-rangeslider { border: 1px solid #EAEAEA; background-color: #EAEAEA; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; border-top-left-radius: 6px; border-top-right-radius: 6px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-hrangeslider { height: 20px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-vrangeslider { width: 20px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjChart from '@grapecity/wijmo.chart'; // import * as Core from '@grapecity/wijmo'; import * as Chart from '@grapecity/wijmo.react.chart'; import * as annotation from '@grapecity/wijmo.chart.annotation'; // import { getData } from './data'; import { EditableAnnotationLayer, Button } from './EditableAnnotationLayer'; import { AxisScrollbar } from './AxisScrollbar'; // class App extends React.Component { // constructor(props) { super(props); this.state = { data: getData(), isEditable: true }; } // render() { return <div className="container-fluid"> <div className="form-group"> <label id="labelIsEditable">編集可能: <input type="checkbox" id="checkboxIsEditable" checked={this.state.isEditable} onChange={this.editableChange.bind(this)}/> </label> <Chart.FlexChart initialized={this.chartInitialized.bind(this)} itemsSource={this.state.data} tooltipContent="" rendered={this.chartRendered.bind(this)} chartType="Scatter" bindingX="x"> <Chart.FlexChartSeries name="データ" binding="y"></Chart.FlexChartSeries> </Chart.FlexChart> </div> </div>; } // editableChange() { if (this.al) { this.setState({ isEditable: !this.state.isEditable }, () => this.al.isEditable = this.state.isEditable); } } // chartInitialized(flex) { this.theChart = flex; let axisScrollBar = new AxisScrollbar(this.theChart.axes[0]); window.setTimeout(function () { axisScrollBar.maxPos = 0.5; }, 20); } // chartRendered() { let al = this.al; if (!al) { al = new EditableAnnotationLayer(this.theChart); this.al = al; al.isEditable = this.state.isEditable; // //add customize button var triangle, triangleBtn = new Button(function (engine) { var triangleIcon = new annotation.Polygon({ tooltip: 'カスタム - 三角 </br>ドラッグして三角の注釈を追加します。', points: [{ x: 10, y: 5 }, { x: 5, y: 15 }, { x: 15, y: 15 }], style: { fill: 'yellow' } }); triangleIcon.render(engine); return triangleIcon._element; }, function (point, isDataCoordinate) { var x = isDataCoordinate ? point.dx : point.x, y = isDataCoordinate ? point.dy : point.y; triangle = new annotation.Polygon({ attachment: isDataCoordinate ? annotation.AnnotationAttachment.DataCoordinate : annotation.AnnotationAttachment.Absolute, tooltip: 'カスタム注釈 - 三角', points: [{ x: x, y: y }, { x: x, y: y }, { x: x, y: y }], style: { fill: 'yellow' } }); al.items.push(triangle); }, function (originPoint, currentPoint, isDataCoordinate) { var ox = isDataCoordinate ? originPoint.dx : originPoint.x, oy = isDataCoordinate ? originPoint.dy : originPoint.y, cx = isDataCoordinate ? currentPoint.dx : currentPoint.x, cy = isDataCoordinate ? currentPoint.dy : currentPoint.y, offsetX = Math.abs(cx - ox), offsetY = cy - oy, isXDate = Core.isDate(ox), isYDate = Core.isDate(oy), oaDate = wjChart.FlexChart._fromOADate; triangle.points.clear(); triangle.points.push({ x: ox, y: isYDate ? oaDate(oy - offsetY) : oy - offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - offsetX) : ox - offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - 0 + offsetX) : ox + offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); }); al.buttons.push(triangleBtn); // //add pre-defined annotations. var watermarker = new annotation.Text({ position: annotation.AnnotationPosition.Left | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, text: 'watermarker', tooltip: 'テキストの透かし', point: { x: 1, y: 1 }, style: { 'fill': '#cccccc', 'font-size': '30px', opacity: 0.2 } }); al.items.push(watermarker); // var imgmarker = new annotation.Image({ position: annotation.AnnotationPosition.Right | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, tooltip: '画像の透かし', point: { x: 0, y: 1 }, width: 128, height: 33, href: 'resources/wijmo-logo-text.png', style: { opacity: 0.2 } }); al.items.push(imgmarker); // var centerHLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.DataCoordinate, position: annotation.AnnotationPosition.Center, content: '垂直線', start: { x: 50, y: 0 }, end: { x: 50, y: 1000 }, style: { 'stroke-width': '2px', stroke: 'green' } }); al.items.push(centerHLine); // var centerVLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.Relative, position: annotation.AnnotationPosition.Center, content: '水平線', start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 }, style: { 'stroke-width': '2px', stroke: 'red' } }); al.items.push(centerVLine); // var topRange = new annotation.Polygon({ attachment: annotation.AnnotationAttachment.Relative, points: [{ x: 0, y: 0 }, { x: 0, y: 0.2 }, { x: 1, y: 0.2 }, { x: 1, y: 0 }], content: '上端の範囲', style: { fill: '#FEF0DB', opacity: 0.5, stroke: '#FEF0DB' } }); al.items.push(topRange); // //flag var pointIndex = 10; ['black', 'blue', 'green', 'red', 'yellow'].forEach(function (v) { var flagSrc = 'resources/flag-' + v + '-icon.png'; var flag = new annotation.Image({ attachment: annotation.AnnotationAttachment.DataIndex, seriesIndex: 0, pointIndex: pointIndex, width: 24, height: 24, href: flagSrc }); al.items.push(flag); pointIndex += 10; }); // var rect = new annotation.Rectangle({ attachment: annotation.AnnotationAttachment.DataCoordinate, point: { x: 10, y: 650 }, width: 120, height: 150, style: { 'stroke-dasharray': '4 4', stroke: 'red' } }); al.items.push(rect); // var circle = new annotation.Circle({ seriesIndex: 0, attachment: annotation.AnnotationAttachment.DataCoordinate, radius: 80, point: { x: 70, y: 350 }, style: { stroke: 'blue', fill: 'blue', opacity: 0.3 } }); al.items.push(circle); } } } // ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Editable Annotations</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-flexchart { margin: 10px 0; } body { margin-bottom: 24pt; } .wj-flexchart .wjanno-editable-layer .wjanno-container { fill: #eee; stroke: #666; stroke-width: 1; } .wj-flexchart .wjanno-editable-layer .wjanno-dc-icon .wjanno-container { fill: #eee; } .wj-flexchart .wjanno-editable-layer .wjanno-icon-selected .wjanno-container { fill: #89E; } .no-selection { user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; } .wj-flexchart { padding-bottom: 25px; } /**** Axis Scrollbar Css *****/ .wj-flexchart .wj-axis-scrollbar-container { position: relative; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-rangeslider { border: 1px solid #EAEAEA; background-color: #EAEAEA; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; border-top-left-radius: 6px; border-top-right-radius: 6px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-hrangeslider { height: 20px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-vrangeslider { width: 20px; } export function getData() { var data = [], numCount = 100; for (var i = 0; i < numCount; i++) { data.push({ x: getRandomValue(100), y: getRandomValue(1000) }); } return data; } // function getRandomValue(max) { return Math.round(Math.random() * max); } <template> <div class="container-fluid"> <div class="form-group"> <label id="labelIsEditable" for="checkboxIsEditable">編集可能:</label> <input type="checkbox" id="checkboxIsEditable" v-model="isEditable" v-on:change="editableChange" /> <wj-flex-chart bindingX="x" chartType="Scatter" :itemsSource="data" tooltipContent="" :rendered="chartRendered" :initialized="chartInitialized"> <wj-flex-chart-series name="データ" binding="y"></wj-flex-chart-series> </wj-flex-chart> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.chart'; import { getData } from './data'; import { EditableAnnotationLayer, Button } from './EditableAnnotationLayer'; import { AxisScrollbar } from './AxisScrollbar'; import * as core from '@grapecity/wijmo'; import * as wjChart from '@grapecity/wijmo.chart'; import * as annotation from '@grapecity/wijmo.chart.annotation'; let App = Vue.extend({ name: 'app', data: function () { return { data: getData(), isEditable: true, al: null } }, methods: { editableChange: function() { if(this.al) { this.al.isEditable = this.isEditable; } }, chartInitialized: function(flex) { this.theChart = flex; let axisScrollBar = new AxisScrollbar(this.theChart.axes[0]); window.setTimeout(function () { axisScrollBar.maxPos = 0.5; }, 20); }, chartRendered: function() { let al = this.al; if (!al) { al = new EditableAnnotationLayer(this.theChart); this.al = al; al.isEditable = this.isEditable; //add customize button var triangle, triangleBtn = new Button(function (engine) { var triangleIcon = new annotation.Polygon({ tooltip: 'カスタム - 三角 </br>ドラッグして三角の注釈を追加します。', points: [{ x: 10, y: 5 }, { x: 5, y: 15 }, { x: 15, y: 15 }], style: { fill: 'yellow' } }); triangleIcon.render(engine); return triangleIcon._element; }, function (point, isDataCoordinate) { var x = isDataCoordinate ? point.dx : point.x, y = isDataCoordinate ? point.dy : point.y; triangle = new annotation.Polygon({ attachment: isDataCoordinate ? annotation.AnnotationAttachment.DataCoordinate : annotation.AnnotationAttachment.Absolute, tooltip: 'カスタム注釈 - 三角', points: [{ x: x, y: y }, { x: x, y: y }, { x: x, y: y }], style: { fill: 'yellow' } }); al.items.push(triangle); }, function (originPoint, currentPoint, isDataCoordinate) { var ox = isDataCoordinate ? originPoint.dx : originPoint.x, oy = isDataCoordinate ? originPoint.dy : originPoint.y, cx = isDataCoordinate ? currentPoint.dx : currentPoint.x, cy = isDataCoordinate ? currentPoint.dy : currentPoint.y, offsetX = Math.abs(cx - ox), offsetY = cy - oy, isXDate = core.isDate(ox), isYDate = core.isDate(oy), oaDate = wjChart.FlexChart._fromOADate; triangle.points.clear(); triangle.points.push({ x: ox, y: isYDate ? oaDate(oy - offsetY) : oy - offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - offsetX) : ox - offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); triangle.points.push({ x: isXDate ? oaDate(ox - 0 + offsetX) : ox + offsetX, y: isYDate ? oaDate(oy - 0 + offsetY) : oy + offsetY }); }); al.buttons.push(triangleBtn); //add pre-defined annotations. var watermarker = new annotation.Text({ position: annotation.AnnotationPosition.Left | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, text: 'watermarker', tooltip: 'テキストの透かし', point: { x: 1, y: 1 }, style: { 'fill': '#cccccc', 'font-size': '30px', opacity: 0.2 } }); al.items.push(watermarker); var imgmarker = new annotation.Image({ position: annotation.AnnotationPosition.Right | annotation.AnnotationPosition.Top, attachment: annotation.AnnotationAttachment.Relative, tooltip: '画像の透かし', point: { x: 0, y: 1 }, width: 128, height: 33, href: 'resources/wijmo-logo-text.png', style: { opacity: 0.2 } }); al.items.push(imgmarker); var centerHLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.DataCoordinate, position: annotation.AnnotationPosition.Center, content: '垂直線', start: { x: 50, y: 0 }, end: { x: 50, y: 1000 }, style: { 'stroke-width': '2px', stroke: 'green' } }); al.items.push(centerHLine); var centerVLine = new annotation.Line({ attachment: annotation.AnnotationAttachment.Relative, position: annotation.AnnotationPosition.Center, content: '水平線', start: { x: 0, y: 0.5 }, end: { x: 1, y: 0.5 }, style: { 'stroke-width': '2px', stroke: 'red' } }); al.items.push(centerVLine); var topRange = new annotation.Polygon({ attachment: annotation.AnnotationAttachment.Relative, points: [{ x: 0, y: 0 }, { x: 0, y: 0.2 }, { x: 1, y: 0.2 }, { x: 1, y: 0 }], content: '上端の範囲', style: { fill: '#FEF0DB', opacity: 0.5, stroke: '#FEF0DB' } }); al.items.push(topRange); //flag var pointIndex = 10; ['black', 'blue', 'green', 'red', 'yellow'].forEach(function (v) { var flagSrc = 'resources/flag-' + v + '-icon.png'; var flag = new annotation.Image({ attachment: annotation.AnnotationAttachment.DataIndex, seriesIndex: 0, pointIndex: pointIndex, width: 24, height: 24, href: flagSrc }); al.items.push(flag); pointIndex += 10; }); var rect = new annotation.Rectangle({ attachment: annotation.AnnotationAttachment.DataCoordinate, point: { x: 10, y: 650 }, width: 120, height: 150, style: { 'stroke-dasharray': '4 4', stroke: 'red' } }); al.items.push(rect); var circle = new annotation.Circle({ seriesIndex: 0, attachment: annotation.AnnotationAttachment.DataCoordinate, radius: 80, point: { x: 70, y: 350 }, style: { stroke: 'blue', fill: 'blue', opacity: 0.3 } }); al.items.push(circle); } } } }) new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .wj-flexchart { margin: 10px 0; } body { margin-bottom: 24pt; } .wj-flexchart .wjanno-editable-layer .wjanno-container { fill: #eee; stroke: #666; stroke-width: 1; } .wj-flexchart .wjanno-editable-layer .wjanno-dc-icon .wjanno-container { fill: #eee; } .wj-flexchart .wjanno-editable-layer .wjanno-icon-selected .wjanno-container { fill: #89E; } .no-selection { user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; } .wj-flexchart { padding-bottom: 25px; } /**** Axis Scrollbar Css *****/ .wj-flexchart .wj-axis-scrollbar-container { position: relative; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-rangeslider { border: 1px solid #EAEAEA; background-color: #EAEAEA; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; border-top-left-radius: 6px; border-top-right-radius: 6px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-hrangeslider { height: 20px; } .wj-flexchart .wj-axis-scrollbar-container .wj-chart-vrangeslider { width: 20px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Editable Annotations</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> export function getData() { var data = [], numCount = 100; for (var i = 0; i < numCount; i++) { data.push({ x: getRandomValue(100), y: getRandomValue(1000) }); } return data; } // function getRandomValue(max) { return Math.round(Math.random() * max); }