add legend in line/bar/area graphs

This commit is contained in:
Fine 2022-11-03 16:14:21 +08:00
parent 42d2545e61
commit 5bfac6fdc9
5 changed files with 50 additions and 21 deletions

View File

@ -95,7 +95,7 @@ export type GraphConfig =
export interface BarConfig {
type?: string;
showBackground?: boolean;
LegendOptions?: LegendOptions;
legend?: LegendOptions;
}
export interface LineConfig extends AreaConfig {
type?: string;
@ -111,7 +111,7 @@ export interface LineConfig extends AreaConfig {
export interface AreaConfig {
type?: string;
opacity?: number;
LegendOptions?: LegendOptions;
legend?: LegendOptions;
}
export interface CardConfig {

View File

@ -13,15 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<template>
<div>
<span class="label">{{ t("showLegend") }}</span>
<el-switch
v-model="legend.showLegend"
active-text="Yes"
inactive-text="No"
@change="updateLegendConfig({ showLegend: legend.showLegend })"
/>
</div>
<div>
<span class="label">{{ t("legendOptions") }}</span>
<span class="title mr-5">{{ t("asTable") }}</span>

View File

@ -13,7 +13,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<template>
<Graph :option="option" @select="clickEvent" :filters="config.filters" />
<div class="graph">
<Graph :option="option" @select="clickEvent" :filters="config.filters" />
<Legend :config="config.legend" :data="data" />
</div>
</template>
<script lang="ts" setup>
import { computed } from "vue";
@ -39,7 +42,8 @@ const props = defineProps({
BarConfig & {
filters: Filters;
relatedTrace: RelatedTrace;
} & { id: string }
id: string;
}
>,
default: () => ({}),
},
@ -160,3 +164,9 @@ function clickEvent(params: EventParams) {
emits("click", params);
}
</script>
<style lang="scss" scoped>
.graph {
width: 100%;
height: 100%;
}
</style>

View File

@ -13,12 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<template>
<Graph
:option="option"
@select="clickEvent"
:filters="config.filters"
:relatedTrace="config.relatedTrace"
/>
<div class="graph">
<Graph
:option="option"
@select="clickEvent"
:filters="config.filters"
:relatedTrace="config.relatedTrace"
/>
<Legend :config="config.legend" :data="data" />
</div>
</template>
<script lang="ts" setup>
import { computed } from "vue";
@ -29,6 +32,7 @@ import {
RelatedTrace,
Filters,
} from "@/types/dashboard";
import Legend from "./components/Legend.vue";
/*global defineProps, defineEmits */
const emits = defineEmits(["click"]);
@ -206,3 +210,9 @@ function clickEvent(params: EventParams) {
emits("click", params);
}
</script>
<style lang="scss" scoped>
.graph {
width: 100%;
height: 100%;
}
</style>

View File

@ -13,6 +13,24 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<template>
<div>legend</div>
<div></div>
</template>
<script lang="ts" setup></script>
<script lang="ts" setup>
import type { PropType } from "vue";
import { LegendOptions } from "@/types/dashboard";
/*global defineProps */
const props = defineProps({
data: {
type: Object as PropType<{ [key: string]: number[] }>,
default: () => ({}),
},
config: {
type: Object as PropType<LegendOptions>,
default: () => ({
legend: {},
}),
},
});
// console.log(props);
</script>